23.01.2026, 18:24
(This post was last modified: 23.01.2026, 18:25 by Dale Yarker.)
Code:
'Second Sample
'
'Works more or less now. With fixed key it is coding not encryption.
'Depending on key a character may be a terminating character.
'For example, 123 cuts the message at 22 characters.
'Left in commented out bad code and some of my MSGBOXes.
'Worst was having both GET and INPUT.
'Is this VERY old? ($register none vs #register none)
'Or is it AI generated?
#compile exe
#dim all
#include "WIN32API.INC"
global hDlg as long
callback function ENDPROG()
dialog end cbhndl, 1
end function
function pbmain () as long
'$register none
local result, i as long
local key as byte
local PlainText, ch, chdecoded as string
'2. XOR Encoding
PlainText = "This is my secret message."
open "testSecret2a.dat" for output as #1 len=len(PlainText) chr=ansi
key = 123 ' Simple numeric key
for i = 1 to len(PlainText)
print #1, chr$(asc(mid$(PlainText, i, 1)) xor key); 'MID$ was missing
next
'' seteof #1
close #1
'XOR is reversible — use the same key to decode.
open "testSecret2a.dat" for input as #1
'' get #1, 1, ch
line input #1, ch
'? dec$(len(ch)),, "length of ch after GET"
chdecoded = ""
key = 123
i = 0
''while not eof(1) 'EOF ???? GET or LINE INPUT does file to string
do
chdecoded = chdecoded + chr$(asc(mid$(ch, i, 1)) xor key) '<<<<: ? chdecoded
incr i
''wend
loop until i = len(ch)
close #1
msgbox chdecoded,,"Decoded"
dialog new 0, "TEST 1", ,, 200, 150, %ws_minimizebox+%ws_sysmenu, 0 to hDlg
control add label, hDlg, 100, "LABEL 1",80, 40, 60, 14,
control add button,hDlg, 202, "&Exit Program",100, 100,55, 14, call ENDPROG
control set focus hDlg, 202
dialog show modal hDlg to result
end function