Sver
Full Member
Posts: 145
|
Post by Sver on Sept 4, 2020 12:36:33 GMT -5
rem Convert code to binair text
rem Use as you please! rem By Marnix Vs
'Ask text from user: input "Enter text > "; code.txt$
print bin$(code.txt$); print
[Confirm] input "Do you want to re-translate (Y/N)? > "; answ.trans$ if answ.trans$ = "N" then _ end
if answ.trans$ = "Y" then print trans$(bin$(code.txt$)) call prog.wait 3 end else goto [Confirm] end if
'Convert each caracter to a binary number. 'The whole ASCII table is one byte consisting 'of eight bits. We'll check each character and convert.
function bin$(txt$) for index = 1 to len(txt$) curr.char$ = mid$(txt$,index,1) asc = asc(curr.char$) if asc = 0 then print "Error! Invalid character."; exit function end if
'The highest number is 255, 'the lowest is 0
byte$ = ""
for i = 1 to 8 if asc mod 2 = 0 then byte$ = byte$ + "0" asc = asc / 2 else byte$ = byte$ + "1" asc = (asc - 1) / 2 end if next i
'We have the byte now, but its 'reverted, as we begun with the 'highest number!
for n = 1 to 8 bin$ = bin$ + mid$(byte$,9 - n,1) next n
'Add a space for the next byte: bin$ = bin$ + chr$(32) next index end function
'This sub is to let the program wait 'for <n> seconds. This handy when the 'mainwin is used but the program is exe.
sub prog.wait n 'Capture the time: time = time$("seconds") wait.num = time + n while time$("seconds") <> wait.num 'Nothing goes here! wend end sub
'This function translates a ASCII byte 'to a valid character (0 - 255).
function trans$(bin$) m = 1 while word$(bin$,m) <> "" char.num = 0 single.byte$ = word$(bin$,m) m = m + 1 'We'll go left to right here. for x = 1 to 8 bit$ = mid$(single.byte$,x,1) select case x case 1 if bit$ = "1" then _ char.num = char.num + 128 case 2 if bit$ = "1" then _ char.num = char.num + 64 case 3 if bit$ = "1" then _ char.num = char.num + 32 case 4 if bit$ = "1" then _ char.num = char.num + 16 case 5 if bit$ = "1" then _ char.num = char.num + 8 case 6 if bit$ = "1" then _ char.num = char.num + 4 case 7 if bit$ = "1" then _ char.num = char.num + 2 case 8 if bit$ = "1" then _ char.num = char.num + 1 end select
next x trans$ = trans$ + chr$(char.num) wend
'We're ready, the text has been 'formed, each character apart. end function
|
|