As late as the night is – I promised myself that I would get in a solid amount of time for coding and found a caesar shift cipher challenge online. The challenge was as follows: You receive a text file with the first line containing two numbers. The first number is the number of lines that are to be performed and the second number is the number-of-shifts in the alphabet. Every line after that contains the sentence that is to be decoded. E.G:

This one was fun! Overall I wouldn’t rank it too difficult – See the python solution below:
def main():
shift = 0
alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N"
,"O","P","Q","R","S","T","U","V","W","X","Y","Z"]
answer = ""
test2 = readFileIn()
for i in test2:
if test2.index(i) == 0:
split = i.split(" ")
shift = int(split[-1])
elif test2.index(i) > 0:
shiftedAlpha = shiftAlphabet(alphabet, shift)
charPosArray = getCharPosition(alphabet, shiftedAlpha, i)
answer = answer + charPosArray+ " "
print(answer)
def readFileIn():
fileObject = open("test1.txt", "r")
fileText = fileObject.read()
fileArray = fileText.split("\n")
return(fileArray)
def shiftAlphabet(alpha, shiftNum):
alphabet = alpha + alpha[:(26-shiftNum)]
for i in range(26-shiftNum):
alphabet.pop(0)
return(alphabet)
def getCharPosition(alpha, shiftedAlpha, readLine):
intermediate = readLine
answer = ""
for c in intermediate:
for a in alpha:
if c == a:
answer = answer + shiftedAlpha[alpha.index(a)]
if c == " ":
answer = answer + " "
if c == ".":
answer = answer + "."
return(answer)
main()


