Moeie586
March 1st, 2011, 11:15 PM
I have to implement a cipher for the straddling checkerboard using Python. For what I have, I don't know if I am on the right track and just made a few errors, or if I am just completely misunderstanding how to execute this..
but here were the instructions:
-You are to ask a user running the program to enter plaintext and strip it of all non-letters. Your program needs to print to the screen the stripped version of plaintext for both testing and grading purposes.
For part 1, you are also to generate a checkerboard (i.e. key). A checkerboard should be implemented in the following manner:
-set up a function that returns a string that consists of the following substrings:
substring 1 is high frequency letters with 2 blanks ('estoniar '), followed by substring 2 which is all the other letters in the alphabet with 2 additional characters . and /
-characters in each substring are randomly scrambled so that each run of this function
-returns a different overall string, e.g. 'a stoin ergqpymzc.jxhvuwfldbk/', 'inoretas mfzdckbyq/jgulp.whxv', 'asn tiore p/dhfucvbgz.wkmyjqlx', etc.
Then, in another function, split the resulting string into 3 substrings of length 10 and find blank positions in substring 1. For testing and grading purposes, this function is to print to the screen the resulting three substrings, as well as index values of both blanks. To find the second blank, use the function rfind (seraches backward in a string).
AND HERE IS MY CODE THAT I HAVE SO FAR:
def checkerboard(plaintext):
string1="estoniar "
string2="bcdfghjklmpquvwxyz./"
plainstripped=''
for ch in plaintext:
if ch.isalpha():
plainstripped=plainstripped+ch
plainstripped=plainstripped.lower()
ciphertext=' '
for ch in plainstripped:
if ch in string1:
idx=string1.index('ch')
ciphertext=ciphertext+idx
elif ch in string2:
idx2=string2.index('ch')
ciphertext=ciphertext+idx2
else:
idx3=string3.index('ch')
ciphertext=ciphertext+idx3
return ciphertext
any help or hints towards the right direction would be great..thanks a lot!
but here were the instructions:
-You are to ask a user running the program to enter plaintext and strip it of all non-letters. Your program needs to print to the screen the stripped version of plaintext for both testing and grading purposes.
For part 1, you are also to generate a checkerboard (i.e. key). A checkerboard should be implemented in the following manner:
-set up a function that returns a string that consists of the following substrings:
substring 1 is high frequency letters with 2 blanks ('estoniar '), followed by substring 2 which is all the other letters in the alphabet with 2 additional characters . and /
-characters in each substring are randomly scrambled so that each run of this function
-returns a different overall string, e.g. 'a stoin ergqpymzc.jxhvuwfldbk/', 'inoretas mfzdckbyq/jgulp.whxv', 'asn tiore p/dhfucvbgz.wkmyjqlx', etc.
Then, in another function, split the resulting string into 3 substrings of length 10 and find blank positions in substring 1. For testing and grading purposes, this function is to print to the screen the resulting three substrings, as well as index values of both blanks. To find the second blank, use the function rfind (seraches backward in a string).
AND HERE IS MY CODE THAT I HAVE SO FAR:
def checkerboard(plaintext):
string1="estoniar "
string2="bcdfghjklmpquvwxyz./"
plainstripped=''
for ch in plaintext:
if ch.isalpha():
plainstripped=plainstripped+ch
plainstripped=plainstripped.lower()
ciphertext=' '
for ch in plainstripped:
if ch in string1:
idx=string1.index('ch')
ciphertext=ciphertext+idx
elif ch in string2:
idx2=string2.index('ch')
ciphertext=ciphertext+idx2
else:
idx3=string3.index('ch')
ciphertext=ciphertext+idx3
return ciphertext
any help or hints towards the right direction would be great..thanks a lot!