Last active
February 11, 2019 23:20
-
-
Save blurbdust/e2faa7d9160a4c8c7cd0d791cf8eaab9 to your computer and use it in GitHub Desktop.
CPRE.331 Lab3 Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
rotors = [['VZBRGITYUPSDNHLXAWMJQOFECK'], | |
['AJDKSIRUXBLHWTMCQGZNPYFVOE'], | |
['ESOVPZJAYQUIRHXLNFTGKDCMWB']] | |
original_rotors = rotors | |
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
def rotate(m, distance): | |
m = str(m) | |
m = m.upper() | |
return m[distance : len(charset)] + m[0 : distance] | |
def print_rotors(rotors): | |
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") | |
print(" _________ _________ _________ ") | |
print(" | | | | ") | |
print(" | {} | {} | {} | ".format(rotors[2][0][26 - 2],rotors[1][0][26 - 2],rotors[0][0][26 - 2])) | |
print(" | {} | {} | {} | ".format(rotors[2][0][26 - 1],rotors[1][0][26 - 1],rotors[0][0][26 - 1])) | |
print(" |---------|---------|---------| ") | |
print(" | {} | {} | | {} | | ".format(rotors[2][0][0] ,rotors[1][0][0] ,rotors[0][0][0] )) | |
print(" |---------|---------|---------| ") | |
print(" | {} | {} | {} | ".format(rotors[2][0][1] ,rotors[1][0][1] ,rotors[0][0][1] )) | |
print(" | {} | {} | {} | ".format(rotors[2][0][2] ,rotors[1][0][2] ,rotors[0][0][2] )) | |
print(" |_________|_________|_________| ") | |
def main(): | |
global rotors | |
index_of_message = 0 | |
message = "hello my name is a long message so we can test the rotating" | |
out = "" | |
for char in message: | |
if (index_of_message > 26): | |
index_of_message = index_of_message % 26 | |
out += "\n" | |
which_rotor = (index_of_message // len(charset)) % len(rotors) | |
index_of_which_rotor = index_of_message % len(charset) | |
out += rotors[which_rotor][0][0] | |
print_rotors(rotors) | |
# move rotor now | |
rotors[which_rotor][0] = rotate(rotors[which_rotor][0], 1) | |
index_of_message += 1 | |
print(out) | |
wait = input("") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment