No worries at all. Once someone posts a comment the comments become hidden by default so as not to ruin it for anyone else. Nice job on solving it and creating a decoder!
def decode(msg, number):
temp = []
for i in msg:
finalnum = ord(i) + number
if finalnum > ord('Z'):
finalnum -=26
elif finalnum < ord('A'):
finalnum +=26
temp.append(chr(finalnum))
return ''.join(temp)
message = input('Type message to encrypt/Decrypt')
while True:
number = input('Type number to shift by, n to close')
if(number.lower() != 'n'):
print(decode(message,int(number)))
else:
print('Laterz')
break;
for i in xrange(1, full_shift):
new_string = ''
for l in string:
dec = ord(l) + i
if dec > top:
dec -= full_shift
new_string += chr(dec)
print "index {}: {}".format(i, new_string)
```
string = 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'
top = ord('Z')
full_shift = top - ord('A') + 1
for i in xrange(1, full_shift):
new_string = ''
for l in string:
dec = ord(l) + i
if dec > top:
dec -= full_shift
new_string += chr(dec)
print "index {}: {}".format(i, new_string)
My first attempt at Python. Not as pretty as the already submitted answers. I tried to add a little bit, by checking to see if the answer contained words in the dictionary. Unfortunately, I ran out of time and had to cheat a bit. Given more time I should check all permutations of the encrypted string to make sure that words can be made all the way across. This will only work if the decrypted string starts with a 4 letter word or greater.
import enchant
import random
def DecryptString(encyptedStr):
possibleSolutions = []
offset = 0
while offset <= 25:
decryptedStr = ""
for char in encyptedStr:
charIndex = charList.index(char)
charIndex = charIndex - offset
if charIndex < 0:
charIndex = charIndex + 26
decryptedStr = decryptedStr + charList[charIndex]
if ContainsAWord(decryptedStr):
possibleSolutions.append(decryptedStr)
offset = offset + 1
return possibleSolutions
def EncryptString(str, offset):
encryptedStr = ""
for char in str:
charIndex = charList.index(char)
charIndex = charIndex + offset
if charIndex > 25:
charIndex = charIndex - 26
encryptedStr = encryptedStr + charList[charIndex]
return encryptedStr
def ContainsAWord(str):
dict = enchant.Dict("en_US")
index = 4
while index <= len(str):
if dict.check(str[:index]):
return True
index = index + 1
return False
charList = ["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"]
encryptedString = "WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU"
print("Possible Decrypted Strings")
for decryptedString in DecryptString(encryptedString):
print(decryptedString)
print()
print("Randomly Encrypted String")
randomlyEncryptedString = EncryptString(decryptedString, random.randint(1,26))
print(randomlyEncryptedString)
print()
print("Possible Decrypted Strings")
for decryptedString in DecryptString(randomlyEncryptedString):
print(decryptedString)
I shouldn't say it only works with 4. You can lower the litmus (index) to 1, you'll just get some false positives. Apparently, "Z" is a word... The more you know.
Comments:
pegleg - 10 years, 8 months ago
TODAYSPROBLEMOFTHEDAYISTOCREATEACAESARCIPHERENCRYPTERANDDECRYPTER
reply permalink
pegleg - 10 years, 8 months ago
You should really let me delete my comments :-X Don't mean to ruin it
reply permalink
Max Burstein - 10 years, 8 months ago
No worries at all. Once someone posts a comment the comments become hidden by default so as not to ruin it for anyone else. Nice job on solving it and creating a decoder!
reply permalink
Pegleg - 10 years, 8 months ago
Python 3.4
reply permalink
Kevin Benton - 10 years, 8 months ago
reply permalink
Daniel - 10 years, 8 months ago
My C# solution
Outputs all permutations for this Caesar cipher.
Today's answer is: TODAYSPROBLEMOFTHEDAYISTOCREATEACAESARCIPHERENCRYPTERANDDECRYPTER
reply permalink
Anonymous - 10 years, 8 months ago
Another one in J.
reply permalink
Anonymous - 10 years, 8 months ago
python 2.7 ``` string = 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'
top = ord('Z') full_shift = top - ord('A') + 1
for i in xrange(1, full_shift): new_string = '' for l in string: dec = ord(l) + i if dec > top: dec -= full_shift new_string += chr(dec) print "index {}: {}".format(i, new_string) ```
reply permalink
Anonymous - 10 years, 8 months ago
whoops! Fixed the formatting... python 2.7
reply permalink
Jt - 10 years, 8 months ago
My first attempt at Python. Not as pretty as the already submitted answers. I tried to add a little bit, by checking to see if the answer contained words in the dictionary. Unfortunately, I ran out of time and had to cheat a bit. Given more time I should check all permutations of the encrypted string to make sure that words can be made all the way across. This will only work if the decrypted string starts with a 4 letter word or greater.
reply permalink
Jt - 10 years, 8 months ago
I shouldn't say it only works with 4. You can lower the litmus (index) to 1, you'll just get some false positives. Apparently, "Z" is a word... The more you know.
reply permalink
Hueho - 10 years, 8 months ago
reply permalink