Vigenère cipher/Cryptanalysis: Difference between revisions

m
(J draft)
m (→‎{{header|Wren}}: Minor tidy)
 
(2 intermediate revisions by 2 users not shown)
Line 1,021:
uncaesar=: {{ 26&|@-&(AZ i.x)&.(AZ&i.) y }}"0 1
unvigenere=: {{ ' '-.~,x uncaesar"0 1&.|:(-#x) ]\y }}</syntaxhighlight>
 
Here, kasiski finds all 3-grams (sequences of three adjacent letters) which appear more than once, finds all of the distances between nearest pairs of these sequences, and then further pairs each of these distances with all other distances, finding the greatest common divisor of those distance pairs. Finally, these LCDs are ordered by how many times they appear and the most frequent LCD is taken as the kasiski result.
 
uncaesar works by finding the frequency of occurrence of each letter of the alphabet (in alphabetical order), and then each of the 26 rotations of that sequence are compared with a text frequency alphabet (obtained from a wikipedia table). The rotation with the least root-mean-square sum of differences is chosen as the correct location, and its index is reported as a letter of the alphabet (0=A, 1=B, etc.)
 
(And, the length provided by kasiski is used to break out the sequences to be analyzed by uncaesar...)
 
Task example:
Line 3,348 ⟶ 3,354:
{{trans|Kotlin}}
{{libheader|Wren-math}}
{{libheader|Wren-traititerate}}
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Nums
import "./traititerate" for Stepped
import "./str" for Char, Str
import "./fmt" for Fmt
 
var encoded =
9,482

edits