Advertisement
CSenshi

CyberLab - Cryptography (Lambda)

Sep 6th, 2019
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. from itertools import cycle
  2. from string import ascii_lowercase
  3.  
  4. a = 'abcdefghijklmnopqrstuvwxyz'
  5. b = 0x1A
  6.  
  7.  
  8. def encrypt(key, p):
  9.     items = zip(p, cycle(key))
  10.     result = ''
  11.    
  12.     for item in items:
  13.         total = reduce(lambda u, v: a.index(u) + a.index(v), item)
  14.         result += a[total % b]
  15.        
  16.     return result.lower()
  17.  
  18.  
  19. KEY='robinson'
  20. res = 'nsbzrlvrtvbucacaj'
  21.  
  22. decrypt = 'a'*len(res)
  23. print decrypt
  24. for i in range(len(res)):
  25.     for c in ascii_lowercase:
  26.       s = list(decrypt)
  27.       s[i] = c
  28.       decrypt = "".join(s)
  29.       cur_res = encrypt(KEY, decrypt)
  30.       if cur_res[i] == res[i]:
  31.         print decrypt
  32.         break
  33.  
  34. print "\nResult : {}".format(decrypt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement