Skip to content

Commit 34a2c72

Browse files
arjun1299stokhos
authored andcommitted
Hard coded inputs to mixed_keyword cypher (TheAlgorithms#1500)
* Update morse_code_implementation.py * Delete porta_cipher.py * Update mixed_keyword_cypher.py * Mixed keyword cypher added * issue with mixed keyword fixed * no math included * hardcoded inputs * porta cypher added * porta cypher added * commented in mixed keyword according to contrib.md
1 parent 68767b1 commit 34a2c72

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

ciphers/mixed_keyword_cypher.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
def mixed_keyword(key="college", pt="UNIVERSITY"):
2+
"""
3+
4+
For key:hello
5+
6+
H E L O
7+
A B C D
8+
F G I J
9+
K M N P
10+
Q R S T
11+
U V W X
12+
Y Z
13+
and map vertically
14+
15+
>>> mixed_keyword("college", "UNIVERSITY") # doctest: +NORMALIZE_WHITESPACE
16+
{'A': 'C', 'B': 'A', 'C': 'I', 'D': 'P', 'E': 'U', 'F': 'Z', 'G': 'O', 'H': 'B',
17+
'I': 'J', 'J': 'Q', 'K': 'V', 'L': 'L', 'M': 'D', 'N': 'K', 'O': 'R', 'P': 'W',
18+
'Q': 'E', 'R': 'F', 'S': 'M', 'T': 'S', 'U': 'X', 'V': 'G', 'W': 'H', 'X': 'N',
19+
'Y': 'T', 'Z': 'Y'}
20+
'XKJGUFMJST'
21+
"""
22+
key = key.upper()
23+
pt = pt.upper()
24+
temp = []
25+
for i in key:
26+
if i not in temp:
27+
temp.append(i)
28+
l = len(temp)
29+
# print(temp)
30+
alpha = []
31+
modalpha = []
32+
# modalpha.append(temp)
33+
dic = dict()
34+
c = 0
35+
for i in range(65, 91):
36+
t = chr(i)
37+
alpha.append(t)
38+
if t not in temp:
39+
temp.append(t)
40+
# print(temp)
41+
r = int(26 / 4)
42+
# print(r)
43+
k = 0
44+
for i in range(r):
45+
t = []
46+
for j in range(l):
47+
t.append(temp[k])
48+
if not (k < 25):
49+
break
50+
k += 1
51+
modalpha.append(t)
52+
# print(modalpha)
53+
d = dict()
54+
j = 0
55+
k = 0
56+
for j in range(l):
57+
for i in modalpha:
58+
if not (len(i) - 1 >= j):
59+
break
60+
d[alpha[k]] = i[j]
61+
if not k < 25:
62+
break
63+
k += 1
64+
print(d)
65+
cypher = ""
66+
for i in pt:
67+
cypher += d[i]
68+
return cypher
69+
70+
71+
print(mixed_keyword("college", "UNIVERSITY"))

0 commit comments

Comments
 (0)