Private static String splitIntoLines(int numLines, String message, boolean encrypted) Lines = lines.substring(1) ĭirection *= lineCount = 0 || lineCount = key - 1 ? -1 : 1 String letter = String.valueOf(lines.charAt(0)) * Add first letter to result by removing it from the line */ * condense zig-zag array into normal string */įor (int i = 0 i < message.length() i) Lines = lines.replaceFirst("\\?", letter) String letter = String.valueOf(message.charAt(charCount)) String lines = splitIntoLines(key, message, true) Public static String decrypt(int key, String message) String lines = splitIntoLines(key, message, false) Public static String encrypt(int key, String message) This was ultra fun! Here's my Java solution: public class RailFenceCipher _ -> putStrLn "Usage: (enc|dec) number string" In reduce is (y:l) (overi i xs (const ys)) Where build (x:xs) l (i:is) = build xs (overi i l (x:)) is $ reverse build s (replicate n "") (sort $ take (length s) $ zigzag n) Decided against golfing that and make it actually readable Zigzag n = cycle $ ĭecode n s = reverse $ reduce (zigzag n) "" ScrewGHC = error "'cause GHC likes to complain, but `is' is infinite" The basic idea was rather simple, but it turned out that it wasn't possible to use Haskell's zipWith or a fold with it, so it didn't exactly turn out as I wanted. Kinda unelegant but working Haskell solution. Unsigned int key = stoi(input.substr(input.find_first_of(' '), input.find_last_of(' '))) String message = input.substr(input.find_last_of(' ') 1) String command = input.substr(0, input.find_first_of(' ')) String::const_iterator cipherIter = cipherText.begin() įor (int index = row index < result.size() index = (isTrough ? troughSkips : peakSkips)) String decode(const string
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |