-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoder.py
More file actions
76 lines (74 loc) · 2.21 KB
/
coder.py
File metadata and controls
76 lines (74 loc) · 2.21 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
##Nathan Hinton
from string import ascii_lowercase as alphabet
from random import randint as rint
alphabet = list(alphabet)
class adderMethod:
def __init__(self):
pass
def encode():
message = input("Message: ")
final = ''
for char in message:
if char == ' ':
final+=',.'
elif char in alphabet:
offset = rint(1, 5)
position = alphabet.index(char)
newChar = position - offset
final += (str(alphabet[newChar])+str(offset))
else:
final += char
print(final)
def decode():
x = 1
message = input("Message to decode: ")
final = ''
for char in message:
if char == ',':
final+=' '
elif char in alphabet:
try:
offset = int(message[x])
except ValueError:
print("ERROR!")
break
position = alphabet.index(char)
newChar = (position + offset)%26
print(newChar)
final += alphabet[int(newChar)]
else:
pass
x += 1
print(final)
class shifter:
def __init__(self):
pass
def encode():
message = input("Message: ")
shiftNumber = int(input("Shift number: "))
output = ''
for char in message:
if char in alphabet:
place = alphabet.index(char)
newPlace = place + shiftNumber
output += alphabet[(newPlace%26)]
else:
output += char
print(output)
def decode():
message = input("Message: ")
shiftNumber = int(input("Shift number: "))
output = ''
for char in message:
if char in alphabet:
place = alphabet.index(char)
newPlace = place - shiftNumber
output += alphabet[newPlace]
else:
output += char
print(output)
class piCode:
def __init__(self):
self.pi = int(open('pi', 'r').read())
def encode():
message = input("Message: ")