forked from shivangdubey/HacktoberFest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPseudoRandomSeriesEncrypter.py
129 lines (115 loc) · 3.34 KB
/
PseudoRandomSeriesEncrypter.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# A highly secure encrypter based on pseudo random series logic
# Author: cyberGhoulK
import time
def ceaser_cipher(msg, key1):
a = "abcdefghijklmnopqrstuvwxyz"
c = a.upper()
b = "!@#$%^&*(){}[] ?><.,:;|/*-+_\'\""
enc = ''
key = int(key1 % 26)
for char in msg:
if char in b:
enc += char
elif char in c:
pos = c.find(char)
newpos = (pos + key) % 26
newchar = c[newpos]
enc += newchar
else:
pos = a.find(char)
newpos = (pos + key) % 26
newchar = a[newpos]
enc += newchar
return enc
def ceaser_cipher_d(msg, key):
a = "abcdefghijklmnopqrstuvwxyz"
c = a.upper()
b = "!@#$%^&*() {}[]?><.,:;|/*-+_\'\""
de = ''
key = int(key % 26)
for char in msg:
if char in b:
de += char
elif char in c:
pos = c.find(char)
newpos = (pos - key) % 26
newchar = c[newpos]
de += newchar
else:
pos = a.find(char)
newpos = (pos - key) % 26
newchar = a[newpos]
de += newchar
return de
def generateNxtNumber(seed):
seed = int(seed)
if seed == 0 or seed == 1:
seed = seed + 2
new_num = seed * seed
string_num = str(new_num)
if len(string_num) > 4:
while len(string_num) <= 8:
string_num = '0' + string_num
final_num = string_num[2:6] # 01 2345 67
else:
while len(string_num) != 4:
string_num = '0' + string_num
final_num = string_num
return final_num
def encrypt(msg, seed):
enc = ""
enc_key = ""
for i, ch in enumerate(msg):
if ch == " ":
enc += ch
continue
if i % 2 == 0:
enc_key = generateNxtNumber(seed)
key = int(enc_key[:2])
enc += ceaser_cipher(ch, key)
else:
key = int(enc_key[2:])
enc += ceaser_cipher(ch, key)
seed = int(enc_key)
return enc
def decrypt(enc, seed):
mesg = ""
enc_key = ""
for i, ch in enumerate(enc):
if ch == " ":
mesg += ch
continue
if i % 2 == 0:
enc_key = generateNxtNumber(seed)
key = int(enc_key[:2])
mesg += ceaser_cipher_d(ch, key)
else:
key = int(enc_key[2:])
mesg += ceaser_cipher_d(ch, key)
seed = int(enc_key)
return mesg
def re():
sc_key = 0
m = input("Encrypt(enter:e)\nDecode(enter:d)\n")
m = m.lower()
if m == "e":
message = input("Enter Message to be encrypted:\n")
seed = int(input("Enter a encryption seed(pin) : "))
encrypted_out = encrypt(message, seed)
print("Encrypted_message:\n%s" % (encrypted_out))
elif m == "d":
encrypted_in = input("Enter Message to be decrypted:\n")
seed = int(input("Enter a decryption seed(pin) : "))
mesg = decrypt(encrypted_in, seed)
print("decoded_message:\n%s" % (mesg))
repeat = input("\nAny thing else?\n")
repeat = repeat.lower()
if repeat == "ya" or repeat == "yes" or repeat == "yeah" or repeat == "y":
re()
else:
print("Happy to serve you.")
return
print('Welcome to the Engima')
time.sleep(1.0)
print("\nHello, what do you want to do today?")
re()