Skip to content

Commit 75936bf

Browse files
author
buckminst
committed
(buckminst) ADFGVX modular commit, round 2
1 parent ff66df5 commit 75936bf

File tree

1 file changed

+10
-55
lines changed

1 file changed

+10
-55
lines changed

adfgvx.py

+10-55
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ def __init__(self, worktext, transposekey):
1212
self.worktext = worktext
1313
self.transposekey = transposekey
1414

15-
def encrypt(self):
16-
print "ADFGVX encryption subshell."
15+
def showenviron(self):
16+
print
17+
print "Current ADFGVX work environment"
18+
print "-------------------------------"
1719
print "Base Alphabet:",
1820
print self.base_alphabet
19-
print "\nBlock Cipher:"
21+
print
22+
print "Block Cipher:"
2023
print " ADFGVX"
2124
print " ------"
22-
print "A|"
25+
print "A|",
2326
print "".join(self.alpha_key[0])
2427
print "D|",
2528
print "".join(self.alpha_key[1])
@@ -31,12 +34,12 @@ def encrypt(self):
3134
print "".join(self.alpha_key[4])
3235
print "X|",
3336
print "".join(self.alpha_key[5])
37+
print
3438

39+
def encrypt(self):
3540
plain_string=self.worktext.lstrip().rstrip().lower()
3641
trans_string=self.transposekey.lstrip().rstrip().lower()
3742

38-
print "Parsing input string..."
39-
4043
key_string = ""
4144
for i in range(0,len(plain_string)):
4245
char_loc_c = 0
@@ -58,11 +61,6 @@ def encrypt(self):
5861
key_len = len(key_string_new)
5962
key_pos = 0
6063

61-
for i in range(0,len(trans_string)):
62-
print trans_string[i],
63-
print
64-
print "- - - - - -"
65-
6664
msg_block_c = list()
6765
while key_pos < key_len:
6866
cur_line = ""
@@ -75,7 +73,6 @@ def encrypt(self):
7573
break
7674
key_pos = key_pos + 1
7775
cur_line = cur_line.rstrip()
78-
print cur_line
7976
msg_block_c.append(cur_list)
8077

8178
trans_list = list()
@@ -95,11 +92,6 @@ def encrypt(self):
9592

9693
trans_list.sort()
9794
sorted_string = "".join(trans_list)
98-
print
99-
for i in range(0,len(sorted_string)):
100-
print sorted_string[i],
101-
print
102-
print "- - - - - -"
10395

10496
msg_block_t = list()
10597
for i in range(0,len(msg_block_c)):
@@ -113,7 +105,6 @@ def encrypt(self):
113105
cur_line = cur_line + " "
114106
cur_list.append(" ")
115107
pass
116-
print cur_line
117108
msg_block_t.append(cur_list)
118109

119110
final_string = ""
@@ -126,35 +117,13 @@ def encrypt(self):
126117
pass
127118
final_string = final_string + " "
128119

129-
print
130-
print "Encrypted message string is: " + final_string
131120
return final_string
132121

133122

134123
def decrypt(self):
135-
print "ADFGVX decryption subshell."
136-
print "Base Alphabet:",
137-
print self.base_alphabet
138-
print "\nBlock Cipher:"
139-
print " ADFGVX"
140-
print " ------"
141-
print "A|",
142-
print "".join(self.alpha_key[0])
143-
print "D|",
144-
print "".join(self.alpha_key[1])
145-
print "F|",
146-
print "".join(self.alpha_key[2])
147-
print "G|",
148-
print "".join(self.alpha_key[3])
149-
print "V|",
150-
print "".join(self.alpha_key[4])
151-
print "X|",
152-
print "".join(self.alpha_key[5])
153-
154124
cypher_string=self.worktext.lstrip().rstrip().lower()
155125
trans_string=self.transposekey.lstrip().rstrip().lower()
156126

157-
print "Decrypting..."
158127
cypher_list = cypher_string.split(" ")
159128

160129
trans_list = list()
@@ -181,31 +150,18 @@ def decrypt(self):
181150

182151

183152
sorted_string = "".join(sorted_list)
184-
print
185-
for i in range(0,len(sorted_string)):
186-
print sorted_string[i],
187-
print
188-
print "- - - - - -"
189153

190154
for i in range(0, max_line_len):
191155
cur_line = ""
192156
for j in range(0, len(sorted_string)):
193157
cur_line = cur_line + msg_block_d[sorted_string[j]][i] + " "
194-
print cur_line
195-
196-
print
197-
for i in range(0,len(trans_string)):
198-
print trans_string[i],
199-
print
200-
print "- - - - - -"
201158

202159
index_string = ""
203160
for i in range(0, max_line_len):
204161
cur_line = ""
205162
for j in range(0, len(trans_string)):
206163
cur_line = cur_line + msg_block_d[trans_string[j]][i] + " "
207164
index_string = index_string + msg_block_d[trans_string[j]][i]
208-
print cur_line
209165
index_string.rstrip()
210166

211167
final_string = ""
@@ -219,15 +175,14 @@ def decrypt(self):
219175
except ValueError:
220176
pass
221177

222-
print
223-
print "Decrypted message string is: " + final_string
224178
return final_string
225179

226180
if __name__ == '__main__':
227181
textToHandle = sys.argv[1]
228182
transKey = sys.argv[2]
229183

230184
myADFGVX = ADFGVX(textToHandle, transKey)
185+
myADFGVX.showenviron()
231186
cryptString = myADFGVX.encrypt()
232187
print "Encrypt: ", textToHandle, " -> ", cryptString
233188

0 commit comments

Comments
 (0)