-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrpyt.py
More file actions
42 lines (36 loc) · 712 Bytes
/
Copy pathencrpyt.py
File metadata and controls
42 lines (36 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import binascii
def readKey():
f=open("keys/keyA.txt","r")
key = f.readline()
key = key.strip()
f.close()
return key
def crypt(key):
i = 0
c_msg = ''
for letter in msg:
k = int((key[i%len(key)]))
c_msg += str(int(letter) ^ k)
i += 1
return c_msg
def writeText(cipher):
ff=open("ciphertext.txt", "wb")
ff.write(cipher)
ff.close()
def eraseKey():
f=open("keys/keyA.txt", "r")
firstL= f.readline()
lines=f.readlines()
f.close()
f=open("keys/keyA.txt", "w")
for line in lines:
if line!=firstL:
f.write(line)
f.close()
msg = raw_input("Type a text: ")
msg = bin(int(binascii.hexlify(msg), 16))
msg = msg[2:]
a = readKey()
writeText(crypt(a))
eraseKey()
print "Encryption success"