Created
July 22, 2015 15:04
-
-
Save alicemaz/b1ade2c2fc909f9ae402 to your computer and use it in GitHub Desktop.
original xor thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(alice). | |
-export([decrypt_xor/1]). | |
decrypt_xor(Text) -> | |
Strings = lists:map(fun(N) -> | |
{N, char_distro([X bxor N || X <- Text])} end, lists:seq(0,255)), | |
[{Key,_}|_] = lists:reverse(lists:keysort(2, Strings)), | |
[X bxor Key || X <- Text]. | |
char_distro(Text) -> | |
Freqs = [ | |
{101, 12.5},{116, 9.3},{97, 8.0},{111, 7.6},{105, 7.5},{110, 7.2},{115, 6.5},{114, 6.3}, | |
{104, 5.0},{108,4.0},{100,3.8},{99,3.3},{117,2.7},{109,2.5},{102,2.4},{112,2.1},{103,1.9}, | |
{119,1.7},{121,1.7},{98,1.5},{118,1.0},{107,0.5},{120,0.2},{106,0.2},{113,0.1},{122,0.1},{32,5.0} | |
], | |
(lists:sum(lists:map(fun(N) -> case lists:keyfind(N,1,Freqs) of {N,M} -> M; _ -> 0 end end, Text))/length(Text)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment