Guest User

cipher

a guest
Oct 14th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.46 KB | None | 0 0
  1. print('')
  2. print(Bcolors.GN + " //--------------------------------------------//")
  3. print(Bcolors.GN + " //                _                           //")
  4. print(Bcolors.GN + " //        _      | |                   __     //")
  5. print(Bcolors.GN + " //    ___(_)_ __ | |__   ___ _ __    /[__]\  //")
  6. print(Bcolors.GN + " //   / __| | '_ \| '_ \ / _ \ '__|  |      |  //")
  7. print(Bcolors.GN + " //  | (__| | |_) | | | |  __/ |     |  ()  |  //")
  8. print(Bcolors.GN + " //   \___|_| .__/|_| |_|\___|_|      \____/   //")
  9. print(Bcolors.GN + " //         |_|                                //")
  10. print(Bcolors.GN + " //                                            //")
  11. print(Bcolors.GN + " //  0110011101101111       Coded by explorer  //")
  12. print(Bcolors.GN + " //--------------------------------------------//" + "\n" + "\n")
  13.  
  14. print(Bcolors.Y + ' 1] - кодировать')
  15. print(Bcolors.Y + ' 2] - декодировать')
  16. print(Bcolors.Y + ' 3] - создать новый ключ')
  17. print(Bcolors.Y + ' 4] - справка'+'\n')
  18.  
  19. # encoder
  20. list_encoder = '''%Ёеуъ? 2v#;<\9}иЧRЯfA№e4УАЖn|=ёюя`ИLBНМ_ЪC0~ZwIHбпr'cbdqдgзВ"$Dэlхй,С-XF{Os(:БTжГ6zшЬJьkрpKEШЮХ]uGнЩ[YДQРт)W5N8U.7фxФ/ЛV!чiS1tЕТ3мjоЗmг^aвЭщPцскКПО&hMыа@yлЙoЦ+>*Ы'''
  21. # encoder2
  22. list_encoder2 = '''豸果禾申若念页祭瓜鸟龟足守电麦危幸曲実委用苦玄走武州巻立直虍捨网表岸各釆印担枚耒皮玉甩底瓦具述取而羊肉糸承因在艮性缶赤生考採並老長豕至甲机矛官向効府周件制版穴協板舌済定臼参宝石居波自角貝泣成呼共行令刷枝昔玊交白宇受岩法舟西龙季拝甘乳存襾耳再固艸宙血見聿次里治灰婦目身非禸田司米放宅妻衣刻由卒羽争邑供寺招的全券式舛虫酉毒宿届河'''
  23. # list_encoder3
  24. list_encoder3 = '''表昔龙石各守交枝具刻邑次瓦赤穴州周委協見担曲婦豸羽艮司危寺立府玄券参宝釆页的受乳武宅印呼玉艸在自岸令非老甩述実甲河波法皮糸由成宇白鸟虫虍麦舌申网定固制聿取甘妻宙幸巻缶岩龟承禸直存放生襾供豕共治舟身衣全泣貝耒官耳再刷矛走向果目玊若舛効考用念版电苦式机並長西居足酉羊性灰肉血瓜季臼件拝届毒里至禾米而争枚招行卒因角板底田祭採済捨宿'''
  25. # encoder4
  26. list_encoder4 = '''向米里存糸禾苦果次玉招成巻周届酉非卒河乳承禸定宇治述曲白供司老念目豕式波刻実羊泣府法瓜武舌釆网版玊聿石襾舟直具宅採再角妻虍毒缶血争鸟刷衣行寺官虫肉甘板長因危取耒印底協在足岩西自済臼豸季皮制甩艸龙龟矛考艮昔瓦見受用宿身各居邑祭並枝拝若走申全捨放岸由令舛呼电委券宝幸生担宙表穴効枚交机玄甲性赤件共耳立羽的麦而州婦灰貝至守固页参田'''
  27.  
  28.  
  29. def readme():
  30.     try:
  31.         handle = open("readme.txt", "r")
  32.         data = handle.read()
  33.         print(Bcolors.GN + data)
  34.         handle.close()
  35.     except IOError:
  36.         print(Bcolors.R + 'Файл справки не обнаружен!')
  37.  
  38.  
  39. # new key
  40. def key():
  41.     w = list_encoder
  42.     q = ''.join(random.sample(w, len(w)))
  43.     print('')
  44.     print(Bcolors.GN + q)
  45.  
  46.  
  47. def enc():
  48.     while True:
  49.         b = input('\n' + 'Введите текст для encoder: '+'\n')
  50.         if b == '':
  51.             print(Bcolors.R + "Ничего не введено!")
  52.             continue
  53.  
  54.         h = b + list_encoder
  55.         if len(list_encoder) != len(set(h)):
  56.             print(Bcolors.R + 'Символы в ключе не найдены!')
  57.             continue
  58.         print(Bcolors.GN + '\n' + 'Зашифрованный текст:' + '\n')
  59.  
  60.         i = 1
  61.         for c in b:
  62.             encoder = ''
  63.             y = list_encoder.index(c)
  64.             if i % 3 == 0:
  65.                 encoder += list_encoder4[y]
  66.             elif i % 2 == 0:
  67.                 encoder += list_encoder3[y]
  68.             else:
  69.                 encoder += list_encoder2[y]
  70.             i += 1
  71.             print(encoder, end="")
  72.         break
  73.  
  74.  
  75. def dec():
  76.     while True:
  77.         m = input('\n' + 'Введите текст для decoder: '+'\n')
  78.         if m == '':
  79.             print(Bcolors.R + "Ничего не введено!")
  80.             continue
  81.  
  82.         t = m + list_encoder2
  83.         if len(list_encoder2) != len(set(t)):
  84.             print(Bcolors.R + 'Символы в ключе не найдены!')
  85.             continue
  86.         print(Bcolors.GN + '\n' + 'Расшифрованный текст:' + '\n')
  87.  
  88.         i = 1
  89.         for x in m:
  90.             decoder = ''
  91.             if i % 3 == 0:
  92.                 y = list_encoder4.index(x)
  93.                 decoder += list_encoder[y]
  94.             elif i % 2 == 0:
  95.                 y = list_encoder3.index(x)
  96.                 decoder += list_encoder[y]
  97.             else:
  98.                 y = list_encoder2.index(x)
  99.                 decoder += list_encoder[y]
  100.             i += 1
  101.             print(decoder, end="")
  102.         break
  103.  
  104.  
  105. while True:
  106.     text_vybor = input('Выберите действие:'+'\n')
  107.     if text_vybor == "1":
  108.         enc()
  109.         break
  110.     elif text_vybor == "2":
  111.         dec()
  112.         break
  113.     elif text_vybor == "3":
  114.         key()
  115.         break
  116.     elif text_vybor == "4":
  117.         readme()
  118.         break
  119.     else:
  120.         print(Bcolors.R + "Введите 1,2,3 или 4!")
  121.  
  122. print(Bcolors.Y + "\n\nДля выхода нажмите Enter")
  123. input()
Advertisement
Add Comment
Please, Sign In to add comment