Post by xcoder on Oct 31, 2022 4:57:44 GMT
print "########################################"
print " ARC4 Stream Cipher Base 85 Format"
print " This version uses the filedialog function"
print " Email compatible. Uses hex characters for key"
global key$ '************
print:print
print space$(10);" Select an Option: "
print space$(10);" Select (1) for Encrypt"
print space$(10);" Select (2) for Decrypt"
print space$(10);" Select (3) to quit"
input "Enter your choice: ";var
select case var
case 1
call readWriteFile
case 2
call readWriteNext
case 3
call Quit
case else
call invalid
end select
print:print
wait
End
sub KSA
dim S(256)
dim K(256)
i = 0
j = 0
for i = 0 to 255
S(i)= i
next i
for i = 0 to 255
K(i)= asc(mid$(key$,i mod len(key$)+1))
next i
for i = 0 to 255
j = (j+ S(i)+ K(i))mod 256
temp = S(i)
S(i)= S(j)
S(j)= temp
next i
end sub
sub delay
timer 2000, [timertest]
wait
[timertest]
timer 0
end sub
sub hexKey$ keybd$
print "Hex" + space$(5) + "Decimal"
for i = 1 to len(keybd$)step 2
chunk$ = mid$(keybd$,i,2)
byte = hexDec(chunk$)
if byte = 0 then
cls
call invalid
end if
key$ = key$ + chr$(byte)
print chunk$, byte
next i
end sub
sub readWriteFile
input "Enter key code: ";key$
print key$
call KSA
call delay
filedialog "Open text file", "*.txt", infile$
print "File chosen is ";infile$
filedialog "Save As...", "*.txt", outfile$
open infile$ for input as #r
open outfile$ for output as #w
while eof(#r) = 0
input #r, text$
alpha$ = txPRGA$(text$)
print #w, alpha$
wend
close #r
close #w
for i = 0 to 7
print space$(i); "Encrypting"
next i
print ""
print "Process Completed"
end sub
function txPRGA$(inString$)
i = 0 :j = 0
for x = 1 to len(inString$)
i = i + 1
byte = asc(mid$(inString$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
St = (S(i) + S(j))mod 256
k = byte xor St
char$ = char$ + chr$(k)
next x
txPRGA$ = Format85$(char$)
end function
function Format85$(dat$)
Z85$ = "0123456789abcdefghijklmnopqrstuvwxyz" +_ 'divide string
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"
datLenMod = len(dat$) mod 4
if datLenMod then padding = 4 - datLenMod
for x = 1 to padding
dat$ = dat$ + chr$(0)
next x
for x = 1 to len(dat$) step 4
temp$ = mid$(dat$, x, 4)
for y = 1 to 4
conv = (conv * 256) + asc(mid$(temp$, y, 1))
next y
for convCount = 1 to 5
char = (conv mod 85) + 1
chunk$ = mid$(Z85$, char, 1) + chunk$
conv = int(conv / 85)
next convCount
Format85$ = Format85$ + chunk$
chunk$ = ""
next x
Format85$ = left$(Format85$, len(Format85$) - padding)
end function
print "-----------------------------------------------"
sub readWriteNext
input "Enter key code: ";key$
print key$
call KSA
call delay
filedialog "Open text file", "*.txt", infile$
filedialog "Save As...", "*.txt", outfile$
open infile$ for input as #r
open outfile$ for output as #w
while eof(#r) = 0
input #r, text$
alpha$ = unFormat85$(text$)
print #w, alpha$
wend
close #r
close #w
for i = 0 to 7
print space$(i); "Decrypting"
next i
print ""
print "Process Completed"
end sub
function unFormat85$(dat$)
Z85$ = "0123456789abcdefghijklmnopqrstuvwxyz" +_ 'divide string
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"
padChr$ = right$(Z85$, 1)
datLenMod = len(dat$) mod 5
if datLenMod then padding = 5 - datLenMod
for x = 1 to padding
dat$ = dat$ + padChr$
next x
for x = 1 to len(dat$) step 5
temp$ = mid$(dat$, x, 5)
for y = 1 to 5
t$ = mid$(temp$, y, 1)
conv = (conv * 85) + (instr(Z85$, t$) - 1)
next y
for deconvCount = 1 to 4
char = conv mod 256
chunk$ = chr$(char) + chunk$
conv = int(conv / 256)
next deconvCount
unFormat85$ = unFormat85$ + chunk$
chunk$ = ""
next x
pass$ = left$(unFormat85$, len(unFormat85$) - padding)
unFormat85$ = rxPRGA$(pass$)
end function
function rxPRGA$(inString$)
i = 0 :j = 0
for x = 1 to len(inString$)
i = i + 1
byte = asc(mid$(inString$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
St = (S(i) + S(j))mod 256
k = byte xor St
char$ = char$ + chr$(k)
next x
rxPRGA$ = char$
end function
'--------------------------------------------------------------------------------------------------------
sub Quit
print "quiting application"
print "goodbye!"
wait
End
end sub
sub invalid
print "invalid input"
print "Use onlyhex characters for key"
print "Goodbye!"
wait
End
end sub
print " ARC4 Stream Cipher Base 85 Format"
print " This version uses the filedialog function"
print " Email compatible. Uses hex characters for key"
global key$ '************
print:print
print space$(10);" Select an Option: "
print space$(10);" Select (1) for Encrypt"
print space$(10);" Select (2) for Decrypt"
print space$(10);" Select (3) to quit"
input "Enter your choice: ";var
select case var
case 1
call readWriteFile
case 2
call readWriteNext
case 3
call Quit
case else
call invalid
end select
print:print
wait
End
sub KSA
dim S(256)
dim K(256)
i = 0
j = 0
for i = 0 to 255
S(i)= i
next i
for i = 0 to 255
K(i)= asc(mid$(key$,i mod len(key$)+1))
next i
for i = 0 to 255
j = (j+ S(i)+ K(i))mod 256
temp = S(i)
S(i)= S(j)
S(j)= temp
next i
end sub
sub delay
timer 2000, [timertest]
wait
[timertest]
timer 0
end sub
sub hexKey$ keybd$
print "Hex" + space$(5) + "Decimal"
for i = 1 to len(keybd$)step 2
chunk$ = mid$(keybd$,i,2)
byte = hexDec(chunk$)
if byte = 0 then
cls
call invalid
end if
key$ = key$ + chr$(byte)
print chunk$, byte
next i
end sub
sub readWriteFile
input "Enter key code: ";key$
print key$
call KSA
call delay
filedialog "Open text file", "*.txt", infile$
print "File chosen is ";infile$
filedialog "Save As...", "*.txt", outfile$
open infile$ for input as #r
open outfile$ for output as #w
while eof(#r) = 0
input #r, text$
alpha$ = txPRGA$(text$)
print #w, alpha$
wend
close #r
close #w
for i = 0 to 7
print space$(i); "Encrypting"
next i
print ""
print "Process Completed"
end sub
function txPRGA$(inString$)
i = 0 :j = 0
for x = 1 to len(inString$)
i = i + 1
byte = asc(mid$(inString$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
St = (S(i) + S(j))mod 256
k = byte xor St
char$ = char$ + chr$(k)
next x
txPRGA$ = Format85$(char$)
end function
function Format85$(dat$)
Z85$ = "0123456789abcdefghijklmnopqrstuvwxyz" +_ 'divide string
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"
datLenMod = len(dat$) mod 4
if datLenMod then padding = 4 - datLenMod
for x = 1 to padding
dat$ = dat$ + chr$(0)
next x
for x = 1 to len(dat$) step 4
temp$ = mid$(dat$, x, 4)
for y = 1 to 4
conv = (conv * 256) + asc(mid$(temp$, y, 1))
next y
for convCount = 1 to 5
char = (conv mod 85) + 1
chunk$ = mid$(Z85$, char, 1) + chunk$
conv = int(conv / 85)
next convCount
Format85$ = Format85$ + chunk$
chunk$ = ""
next x
Format85$ = left$(Format85$, len(Format85$) - padding)
end function
print "-----------------------------------------------"
sub readWriteNext
input "Enter key code: ";key$
print key$
call KSA
call delay
filedialog "Open text file", "*.txt", infile$
filedialog "Save As...", "*.txt", outfile$
open infile$ for input as #r
open outfile$ for output as #w
while eof(#r) = 0
input #r, text$
alpha$ = unFormat85$(text$)
print #w, alpha$
wend
close #r
close #w
for i = 0 to 7
print space$(i); "Decrypting"
next i
print ""
print "Process Completed"
end sub
function unFormat85$(dat$)
Z85$ = "0123456789abcdefghijklmnopqrstuvwxyz" +_ 'divide string
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"
padChr$ = right$(Z85$, 1)
datLenMod = len(dat$) mod 5
if datLenMod then padding = 5 - datLenMod
for x = 1 to padding
dat$ = dat$ + padChr$
next x
for x = 1 to len(dat$) step 5
temp$ = mid$(dat$, x, 5)
for y = 1 to 5
t$ = mid$(temp$, y, 1)
conv = (conv * 85) + (instr(Z85$, t$) - 1)
next y
for deconvCount = 1 to 4
char = conv mod 256
chunk$ = chr$(char) + chunk$
conv = int(conv / 256)
next deconvCount
unFormat85$ = unFormat85$ + chunk$
chunk$ = ""
next x
pass$ = left$(unFormat85$, len(unFormat85$) - padding)
unFormat85$ = rxPRGA$(pass$)
end function
function rxPRGA$(inString$)
i = 0 :j = 0
for x = 1 to len(inString$)
i = i + 1
byte = asc(mid$(inString$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
St = (S(i) + S(j))mod 256
k = byte xor St
char$ = char$ + chr$(k)
next x
rxPRGA$ = char$
end function
'--------------------------------------------------------------------------------------------------------
sub Quit
print "quiting application"
print "goodbye!"
wait
End
end sub
sub invalid
print "invalid input"
print "Use onlyhex characters for key"
print "Goodbye!"
wait
End
end sub