-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsecurity_of_XOR.sf
More file actions
21 lines (14 loc) · 857 Bytes
/
insecurity_of_XOR.sf
File metadata and controls
21 lines (14 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/ruby
# XOR can be insecure!
var key1 = "a"*64 # Alice key
var key2 = "z"*64 # Bob key
var msg = "Hello world! How are you doing?"
var c1 = (msg ^ key1) # Alice encrypts the message with her private key and sends it to Bob
var c2 = ( c1 ^ key2) # Bob encrypts the encrypted message with his private key and sends the message back to Alice
var c3 = ( c2 ^ key1) # Alice removes her encryption layer and sends the message back to Bob
say (c3 ^ key2) # Bob can now remove his layer of encryption and read the message
# However, this is insecure!
# Someone that intercepts the encrypted messages, can decrypt them!
say (c2 ^ c3) # Alice's private key
say (c1 ^ c2) # Bob's private key
say (c1 ^ c2 ^ c3) # The original message decrypted from the encrypted messages