Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Reverse iterate
- def revpow2(z, c, b):
- if b == 1:
- return -((z-c)**(0.5));
- else:
- return (z-c)**(0.5);
- # Forward iterate
- def fowpow2(z, c):
- return z * z + c;
- # Encrypt bits
- def encrypt_bits(z, c, pt):
- for b in pt:
- z=revpow2(z,c,int(b));
- print(z);
- return z;
- # Decrypts bits
- def decrypt_bits(z, c, n):
- s = ""
- for b in range(n):
- print(z);
- s += "0" if z.real > 0 else "1";
- z = fowpow2(z,c);
- s = s[::-1]; # reverse the bits
- return s;
- # The secret key (c), and origin point (z)
- c = (-.75+.09j);
- z = (0+0j);
- pt0 = "01000001010000010100000101000001";
- n = len(pt0);
- print("c:" + str(c));
- print("z:" + str(z));
- print("n:" + str(n));
- print("");
- print("Encrypt: " + pt0);
- print("______________________________________");
- ct = encrypt_bits(z, c, pt0);
- print("______________________________________");
- print("");
- print("Decrypt");
- print("______________________________________");
- pt1 = decrypt_bits(ct, c, n);
- print("______________________________________");
- print("");
- print("Decrypted: " + pt1);
- if pt0 != pt1: print("DATA CORRUPTED!!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement