(*расшифровка шифра Цезаря*) let secret = "li bra ghflskhu wklv dqg bra nqrz lw, fods brxu kdqgv" let keys = [ for i in 'a'..'z' -> i] let size = keys |> List.length let slice a = let (h::t) = a t @ [h] let decode (word:string) (code:char list) = for x = 0 to word.Length - 1 do let f = List.tryFindIndex (fun e -> word.[x] = e) keys match f with | Some c -> printf "%c" (code.[c]) | None -> printf "%c" (word.[x]) let rec loop (word:string) (code:char list) count = match count with | _ when count > keys.Length -> () | _ -> printfn "\ntry number %d" count let cipher = slice code decode word cipher loop word cipher (count + 1) printfn "decoding Cezar's cipher %s ...\n" secret loop secret (slice keys) 0 printfn "\n"
Запускаем:
try number 20 he xnw cdbhogdq sghr zmc xnw jmnv hs, bkzo xntq gzmcr try number 21 if yox decipher this and yox know it, clap your hands try number 22
Суть шифра в сдвиге алфавита на определенное количество символов.
Все моноалфавитные шрифты легко взламываются, применять их на практике для шифрования не имеет смысла
ОтветитьУдалить