'===========================================================================
' Subject: CipherSaber                        Date: 12-15-02 (  :  )       
'  Author: Paul O. Bartlett                   Code: Qbasic,QB,PDS          
'  Origin: bartlett@smart.net               Packet: ALGOR.ABC
'===========================================================================
'                                                                             
*
' IVTEST.BAS: Test CipherSaber Initialization Vectors                         
*
'                                                                             
*
' Author: Paul O. Bartlett bartlett@smart.net
*
' Codes: QBasic, QuickBasic 4.5 (tested), PDS                                 
*
' Version: 1.1                                                                
*
' Last update: 2002-08-26                                                     
*
'                                                                             
*
'-----------------------------------------------------------------------------*
'                                                                             
*
' CipherSaber and CipherSaber-2 encryption/decryption by Arnold 
Reinhold      *
' are based on the RC-4 cipher by Ron Rivest.  In the CipherSaber 
implemen-   *
' tation, every encrypted file has a uniquely generated Initialization        
*
' Vector (IV) in the first ten bytes.  For any set of files encrypted 
with    *
' the same passphrase, it is absolutely critical that every IV be 
unique.     *
' If two files encrypted with the same passphrase have the same IV, 
then the  *
' way is wide open to cryptanalytic attack.                                   
*
'                                                                             
*
' This little quick and dirty program determines whether or not the IVs 
of a  *
' set of encrypted files are unique.  To use it, just create a text 
file with *
' any editor.  Each line of the file specifies one file whose IV is to 
be     *
' tested.  Create every line of the test file thus:                           
*
'                                                                             
*
' drive:\<path>\filename.ext                                                  
*
'                                                                             
*
' Save the text file under any convenient name and run IVTEST.BAS.  At 
the    *
' prompt, give it the full pathname to the text file, and the program 
will    *
' determine whether the IVs are unique, and if not will tell you which 
files  *
' have duplicate IVs.                                                         
*
'                                                                             
*
' The statements commented out can be used for manual checking: they 
just     *
' generate a humanly-readable file with filenames and Initialization 
Vectors  *
' in displayable hexadecimal.                                                 
*
'                                                                             
*
'******************************************************************************
'
DEFINT A-Z
DIM IV(1 TO 99) AS STRING * 10  ' <== Increase for testing >99 files
INPUT "File list: ", filelist$
filelist$ = UCASE$(filelist$)
testfile = FREEFILE
OPEN filelist$ FOR INPUT AS #testfile
' outfile = FREEFILE
' OPEN "C:\PERSONAL\LIST.IVS" FOR OUTPUT AS #outfile  ' <== Change as 
needed
filenum = 0
WHILE NOT EOF(testfile)
    filenum = filenum + 1
    LINE INPUT #testfile, filename$
    filename$ = UCASE$(filename$)
    nextfile = FREEFILE
    OPEN filename$ FOR BINARY AS #nextfile
        IV(filenum) = INPUT$(10, #nextfile)
    CLOSE #nextfile
    ' PRINT #outfile, RIGHT$("0" + STR$(filenum), 2) + " : ";
    ' FOR i = 1 TO 10
    '     PRINT #outfile, RIGHT$("0" + HEX$(ASC(MID$(IV(filenum), i, 
1))), 2);
    ' NEXT i
    ' PRINT #outfile, " " + filename$
WEND
CLOSE #testfile
' CLOSE #outfile
found$ = "false"
x = filenum - 1
FOR i = 1 TO x
    start = i + 1
    FOR j = start TO filenum
        IF IV(i) = IV(j) THEN
            PRINT "File" + STR$(i) + " has same IV as file" + STR$(j) + 
"."
            found$ = "true"
        END IF
    NEXT j
NEXT i
IF found$ = "false" THEN
    PRINT "All Initialization Vectors are unique."
END IF
SYSTEM
