Post by xcoder on Feb 1, 2021 23:22:24 GMT -5
Print "##############################################"
global key$
code$ = "AAFFE0E1E2" 'hex$
for i = 1 to len(code$)step 2
chunk$ = mid$(code$,i,2)
byte = hexDec(chunk$)
char$ = chr$(byte)
key$ = key$ + chr$(byte)
next i
print " Rolling Code Stream Cipher"
print "Select an Option: "
print "Select (1) for Encrypt"
print "Select (2) for Decrypt"
print "Select (3) to quit"
input "Enter your choice: ";num
select case num
case 1
call Encrypt
case 2
call Decrypt
case 3
print "Goodbye!"
Stop
case else
print "Invalid input"
print "Program Terminated"
call quit
end select
print:print
print "End of Code"
End
sub Encrypt
iv$ = iv10$()
input "File to Read: ";file$
input "File to write: ";file2$
open file$ for input as #1
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Encode$(txt$,iv$);
close #1
close #2
for i = 1 to 6
print space$(i);"Encrypting"
next
print "------------completed----------------"
end sub
sub Decrypt
input "File to Read: ";file$
input "File to write: ";file2$
open file$ for input as #1
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Decode$(txt$)
close #1
close #2
for i = 1 to 6
print space$(i);"Decrypting"
next
print " --------------completed-------------------------"
end sub
function Encode$(msg$,iv$)
print iv$ '******************
fkey$ = key$ + iv$
print fkey$ '******************
call KSA$ fkey$
out$ = PRGA$(msg$,iv$)
Encode$ = out$
end function
'============================================================
function Decode$(out$)
ivRx$ = left$(out$,10)
print ivRx$ '******************
rfkey$ = key$ + ivRx$
print rfkey$ '******************
call KSA2$ rfkey$
in$ = PRGA2$(out$)
Decode$ = in$
end function
'=============================================================
sub KSA$ fkey$
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$(fkey$,i mod len(fkey$)+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
function PRGA$(msg$,iv$)
i = 0
j = 0
for x = 1 to len(msg$) 'cannot use varible i or j
byte = asc(mid$(msg$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
k = (S(i) + S(j))mod 256
cipher = byte xor k
ascii$ = ascii$ + chr$(cipher)
next x
PRGA$ = iv$ + ascii$
end function
function iv10$()
for i = 0 to 9
x = int(rnd(1)* 256)
y$ = y$ + chr$(x)
next
iv10$ = y$
end function
'================== receive program ========================================
sub KSA2$ rfkey$
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$(rfkey$,i mod len(rfkey$)+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
function PRGA2$(msg$)
text$ = mid$(msg$,11)
i = 0
j = 0
for x = 1 to len(text$) 'cannot use varible i or j
byte = asc(mid$(text$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
k = (S(i) + S(j))mod 256
cipher = byte xor k
ascii$ = ascii$ + chr$(cipher)
next x
PRGA2$ = ascii$
end function
sub quit
'timer must be encased with a sub to function properly
timer 1000,[done]
wait
[done]
timer 0
End
end sub
global key$
code$ = "AAFFE0E1E2" 'hex$
for i = 1 to len(code$)step 2
chunk$ = mid$(code$,i,2)
byte = hexDec(chunk$)
char$ = chr$(byte)
key$ = key$ + chr$(byte)
next i
print " Rolling Code Stream Cipher"
print "Select an Option: "
print "Select (1) for Encrypt"
print "Select (2) for Decrypt"
print "Select (3) to quit"
input "Enter your choice: ";num
select case num
case 1
call Encrypt
case 2
call Decrypt
case 3
print "Goodbye!"
Stop
case else
print "Invalid input"
print "Program Terminated"
call quit
end select
print:print
print "End of Code"
End
sub Encrypt
iv$ = iv10$()
input "File to Read: ";file$
input "File to write: ";file2$
open file$ for input as #1
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Encode$(txt$,iv$);
close #1
close #2
for i = 1 to 6
print space$(i);"Encrypting"
next
print "------------completed----------------"
end sub
sub Decrypt
input "File to Read: ";file$
input "File to write: ";file2$
open file$ for input as #1
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Decode$(txt$)
close #1
close #2
for i = 1 to 6
print space$(i);"Decrypting"
next
print " --------------completed-------------------------"
end sub
function Encode$(msg$,iv$)
print iv$ '******************
fkey$ = key$ + iv$
print fkey$ '******************
call KSA$ fkey$
out$ = PRGA$(msg$,iv$)
Encode$ = out$
end function
'============================================================
function Decode$(out$)
ivRx$ = left$(out$,10)
print ivRx$ '******************
rfkey$ = key$ + ivRx$
print rfkey$ '******************
call KSA2$ rfkey$
in$ = PRGA2$(out$)
Decode$ = in$
end function
'=============================================================
sub KSA$ fkey$
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$(fkey$,i mod len(fkey$)+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
function PRGA$(msg$,iv$)
i = 0
j = 0
for x = 1 to len(msg$) 'cannot use varible i or j
byte = asc(mid$(msg$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
k = (S(i) + S(j))mod 256
cipher = byte xor k
ascii$ = ascii$ + chr$(cipher)
next x
PRGA$ = iv$ + ascii$
end function
function iv10$()
for i = 0 to 9
x = int(rnd(1)* 256)
y$ = y$ + chr$(x)
next
iv10$ = y$
end function
'================== receive program ========================================
sub KSA2$ rfkey$
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$(rfkey$,i mod len(rfkey$)+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
function PRGA2$(msg$)
text$ = mid$(msg$,11)
i = 0
j = 0
for x = 1 to len(text$) 'cannot use varible i or j
byte = asc(mid$(text$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
k = (S(i) + S(j))mod 256
cipher = byte xor k
ascii$ = ascii$ + chr$(cipher)
next x
PRGA2$ = ascii$
end function
sub quit
'timer must be encased with a sub to function properly
timer 1000,[done]
wait
[done]
timer 0
End
end sub