java - Breaking The Caesar Cipher -
import java.util.scanner; public class caesarcipher { public static void main(string[] args) { // todo auto-generated method stub scanner input = new scanner (system.in); system.out.println("enter encrypted text :"); string cryptedtext = input.nextline(); cryptedtext = cryptedtext.tolowercase(); string[] array = new string[cryptedtext.length()]; (int = 97; < 123; i++) { int mostfrequent = 0; (int j = 0; j < cryptedtext.length(); j++) { if (cryptedtext.charat(j) == i){ ++mostfrequent; } } system.out.println((char) + " showing " + mostfrequent + " times "); } } }
i trying break cipher , have count how many times 1 letter repeats self in word or sentence. need turn crypt word/sentence actual sentence in english , don't know how it. have write encrypt , count letters repeating ( far have done ),but don't know how decrypt it.
caesar cipher encrypts message shifting letters (a-z) known key. there 26 characters, resulting in 26 possibilities. brute force approach scan simplest possible keys (1-26) generating decrypted text each. 1 of decrypted texts readable , solution. there won't need use word frequency in case. next step challenge telling computer how pick solution you.
pseudo-code
key=1 while key<27 create string/array of letters shifted key print/store results + key increment key
Comments
Post a Comment