{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b329650",
   "metadata": {},
   "outputs": [],
   "source": [
    "PERSIAN_ALPHABET = \"ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی\"\n",
    "\n",
    "def persian_caesar_cipher(text, shift, mode='encode'):\n",
    "    result = \"\"\n",
    "    alphabet_size = len(PERSIAN_ALPHABET)\n",
    "    \n",
    "    if mode == 'decode':\n",
    "        shift = -shift\n",
    "        \n",
    "    for char in text:\n",
    "        if char in PERSIAN_ALPHABET:\n",
    "            current_index = PERSIAN_ALPHABET.index(char)\n",
    "            \n",
    "            new_index = (current_index + shift) % alphabet_size\n",
    "            \n",
    "            result += PERSIAN_ALPHABET[new_index]\n",
    "        else:\n",
    "            result += char\n",
    "            \n",
    "    return result\n",
    "\n",
    "def main():\n",
    "    clear_screen()\n",
    "    print(\"--- 🔐 به سیستم رمزنگاری فارسی خوش آمدید ---\")\n",
    "    \n",
    "    while True:\n",
    "        print(\"\\n1. رمزگذاری پیام (Encode)\")\n",
    "        print(\"2. رمزگشایی پیام (Decode)\")\n",
    "        print(\"3. خروج\")\n",
    "        \n",
    "        choice = input(\"\\nانتخاب شما: \")\n",
    "        \n",
    "        if choice in ['1', '2']:\n",
    "            message = input(\"متن فارسی را وارد کنید: \")\n",
    "            try:\n",
    "              \n",
    "                key = int(input(\"کلید رمز (عدد بین 1 تا 31): \"))\n",
    "            except ValueError:\n",
    "                print(\"❌ خطا: کلید باید یک عدد باشد!\")\n",
    "                continue\n",
    "                \n",
    "            mode = 'encode' if choice == '1' else 'decode'\n",
    "            output = persian_caesar_cipher(message, key, mode)\n",
    "            \n",
    "            print(\"\\n\" + \"=\"*30)\n",
    "            print(f\"نتیجه نهایی ({mode}):\")\n",
    "            print(f\"👉 {output}\")\n",
    "            print(\"=\"*30)\n",
    "            \n",
    "        elif choice == '3':\n",
    "            print(\"سیستم بسته شد. خدانگهدار حامد!\")\n",
    "            break\n",
    "        else:\n",
    "            print(\"⚠️ گزینه اشتباه!\")\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7dc5f18a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9cba07a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
