Chris_M_Thomasson

Reverse Iteration Cipher in Python 3

Jul 12th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. # Reverse iterate
  2. def revpow2(z, c, b):
  3.      if b == 1:
  4.             return -((z-c)**(0.5));
  5.      else:
  6.             return (z-c)**(0.5);
  7.  
  8. # Forward iterate
  9. def fowpow2(z, c):
  10.      return z * z + c;
  11.  
  12. # Encrypts a byte
  13. def encrypt_byte(z, c, pt):
  14.     for b in pt:
  15.         z=revpow2(z,c,int(b));
  16.         print(z);
  17.     return z;
  18.  
  19. # Decrypts a byte
  20. def decrypt_byte(z, c):
  21.     s = ""
  22.     for b in range(8):
  23.         print(z);
  24.         s += "0" if z.real > 0 else "1";
  25.         z=fowpow2(z,c);
  26.     s = s[::-1]; # reverse the bits
  27.     return s;
  28.  
  29.  
  30.  
  31.  
  32. # The secret key (c), and origin point (z)
  33. c = (-.75+.09j);
  34. z = (0+0j);
  35. pt0 = "01000001";
  36.  
  37. print("Encrypt: " + pt0);
  38. print("______________________________________");
  39. ct = encrypt_byte(z, c, pt0);
  40. print("______________________________________");
  41.  
  42. print("");
  43.  
  44. print("Decrypt");
  45. print("______________________________________");
  46. pt1 = decrypt_byte(ct, c);
  47. print("______________________________________");
  48.  
  49. print("");
  50.  
  51. print("decrypted: " + pt1);
Advertisement
Add Comment
Please, Sign In to add comment