forked from anshrathod/Basic-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonetimepad.py
More file actions
30 lines (24 loc) · 694 Bytes
/
onetimepad.py
File metadata and controls
30 lines (24 loc) · 694 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
def encode(pText, key):
cText = ""
for i in range(0, len(pText)):
cText += encodeChar(pText[i], key[i])
return cText
def encodeChar(pText, key):
cNum = (charToNum(pText) + charToNum(key)) % 26
cText = numToChar(cNum)
return cText
def charToNum(char):
alphabet = "abcdefghijklmnopqrstuvwxyz"
num = 1
for letter in alphabet:
if letter == char:
break
else:
num += 1
return num
def numToChar(num):
alphabet = "abcdefghijklmnopqrstuvwxyz"
return alphabet[num+1]
pt = str(input("Enter plain text:")).upper()
ky = str(input("Enter key:")).upper()
print(encode(pt, ky))