[118963] in Cypherpunks

home help back first fref pref prev next nref lref last post

Index of Coincidence Awk Program

daemon@ATHENA.MIT.EDU (trusted1@hushmail.com)
Mon Oct 11 13:48:53 1999

From: trusted1@hushmail.com
Message-Id: <199910111722.KAA11797@mail3.hushmail.com>
Date: Mon Oct 11 10:15:31 PDT 1999
To: cypherpunks@toad.com
Reply-To: trusted1@hushmail.com

# pipe in ciphertext.
# this computes index of coincidence to help determine key length.
# perl is better for larger quantities, but this would be fine for
# simple little XOR'd stuffs. 'total' is the actual number of 
#coincidences per attempted shift.
#
#  M1ckF0l3y
# Futile Crew

awk '{
    s1=$0
    for (shift=1;shift<=(length(s1)+1);shift++)
        {
        position=0
        s2=(substr(s1,shift)(substr(s1,1,(shift-1))))
        for (position=1;position<=(length(s1)+1);position++)
            {
            p1=(substr(s1,position,1))
            p2=(substr(s2,position,1))
            if ( p1 == p2 )
               (total = total + 1)
            }
        print (total/length(s1)) " for shift "shift" and total "total
        total=0
        }
}'
   
Get HushMail. The world's first free, fully encrypted, web-based email system.
Speak freely with HushMail.... http://www.hushmail.com


home help back first fref pref prev next nref lref last post