Post by xcoder on Mar 20, 2021 7:15:45 GMT
print "###########"
print " 32 bit integers as sub keys"
global half32
half32 = 2^32/2
randomize 2654435769
for i = 0 to 4
x = int(rnd(1)* 2^32)
K(i) = x
print K(i)
next i
print:print
a = 4222333444 'this represents a 32 bit integer data block
cipher = Encrypt(a)
print cipher
input "Press Enter to Decrypt: ";entry$
print Decrypt(cipher)
print:print
print "End of Code"
End
function Encrypt(a)
for j = 0 to 0 'simulates block of data
' recycled
for i = 0 to 4 'cycle rounds equals same as sub keys
for k = 1 to 4 'sets amout of bit rotation ...
a = rotateLeft(a) 'for substitution box *******
print dec2Bin$(a)
next k
a = a xor K(i) 'allows final value outside of loop
print a
next i
'cycles back
print ""
Encrypt = a
next j
end function
function Decrypt(a)
for j = 0 to 0 'block of data
' recycled
for i = 4 to 0 step -1 'reverse key order for Decrypt
a = a xor K(i) 'allows final value outside of loop
for k = 1 to 4
a = rotateRight(a)
print dec2Bin$(a)
next k
print a
next i
'cycles back
print ""
Decrypt = a
next j
end function
function rotateLeft(b)
rotateLeft = (( 2 *b) mod 2^32) or (b> 2^31-1)
end function
function rotateRight(b)
rotateRight = (half32*( b and 1)) or int(b/2)
end function
function dec2Bin$(num)
n =num
dec2Bin$ =""
while (num >0)
dec2Bin$ =str$( num mod 2) +dec2Bin$
num =int(num /2)
wend
dec2Bin$ =right$( "00000000" +dec2Bin$, 32)
end function
edit: code tags added by Rod. Given the double spacing I think xcoder tried to get the tags right. The forum is abit confusing really with this Preview/BBCode difference. I would love some explanitory words in addition to the code and perhaps a simple demo of using the functions.