-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
104 lines (95 loc) · 3.23 KB
/
main.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from ascii import top, breaker, about, story
import sys
from os import system
system('title '+ 'pyCypher')
#dictionary
dict = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
# functions
# processing
def perform(msg, shift):
new_msg = ''
for letter in msg:
if letter not in dict:
new_msg += letter
else:
position = dict.index(letter)
if opt == 'e':
npos = position + shift
if opt == 'd':
npos = position - shift
new_msg += dict[npos]
print(f'{breaker}\nthe message is ▼\n{new_msg}')
end()
# restarting
def end():
print(breaker)
ans = input('do you want to run again? y/n:\n>>> ')[:1].lower()
if ans == 'y':
state = True
elif ans == 'n':
sys.exit()
else:
print('''>>> unrecognized command.
enter \'y\' or \'n\' only.''')
end()
#brute force
def bf():
msg = input('type your message:\n>>> ').lower()
for x in range(1, 26):
new_msg = ''
for letter in msg:
if letter not in dict:
new_msg += letter
else:
position = dict.index(letter)
numpos = position - x
new_msg += dict[numpos]
print(f'{breaker}\nfor shift num {x}, the message is ▼\n{new_msg}')
end()
# inputing
def cont():
msg = input('type your message:\n>>> ').lower()
try:
shift = int(input('type the shift number:\n>>> '))
if shift > 25:
shift = shift % 25
else:
shift = shift
perform(msg, shift)
except:
print('''>>> error: enter numbers only.
restarting...''')
end()
# main
print(top)
state = True
while state:
opt = input("choose menu:\n>>> ")[:1]
if opt == 'e':
print('► encode')
cont()
elif opt == 'd':
print('► decode')
cont()
elif opt == 'b':
print('► brute force')
bf()
elif opt == 'a':
print(
f'''{story}\n In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher,
Caesar's code or Caesar shift, is one of the simplest and most widely known encryption
techniques. It is a type of substitution cipher in which each letter in the plaintext
is replaced by a letter some fixed number of positions down the alphabet.
\n For example, with a left shift of 3, D would be replaced by A, E would become B,
and so on. The method is named after Julius Caesar, who used it in his private
correspondence.
[source: https://en.wikipedia.org/wiki/Caesar_cipher]
{about}\n► created on 13/Nov/2020\n► a Caesar Cipher en/decoder\n► made with Python3\n► by KIM SONG @CaptKrakenatic''')
end()
elif opt == 'q':
sys.exit()
else:
print('>>> unrecognized command.\n>> here are your choices: e to encode, d to decode, a to read about page, q to quit <<')
state = True