Making text unreadable, 1 sample code works, 2 do not work
#3
Was working (unsuccessfully) on second example. I refreshed and saw Kurt's reply. He is 100% correct but mentioned only one of multiple problems.

Patched up third example with comments:
Code:
#compile exe
#dim all '<<==== good idea always
'This is encrypt/decrypt, though with non-secure random
'
'#INCLUDE "WIN32API.INC" '<<=== ??WHY??, no API calls
global hDlg as dword 'Okay, but no reason here

callback function ENDPROG()
  if (cb.msg = %wm_command) and (cb.ctlmsg = %bn_clicked) _
     and (cb.ctl = 202) then 'left magic number ID
    dialog end cbhndl  ', 1 not using Result here
  end if
end function

function pbmain () as long
''$REGISTER NONE
  local result, i as long
  local mask as byte 'because each ANSI character is byte sized
  local text, decoded, mask1, data1 as string

  '3. Binary Write with Random Mask
  'RANDOMIZE TIMER 'needs same STARTing mask for code and decode
  randomize 123 'extremely weak, testing only
  open "secret 3.dat" for binary as #1
  text = "This is my secret message." 'text is a PB keyword, but works
  for i = 1 to len(text$)
    mask = rnd(1, 255)
    put$ #1, chr$(asc(mid$(text, i, 1)) xor mask)
  next
  close #1

  randomize 123 'use same seed as code
  open "secret 3.dat" for binary as #1
  decoded = ""
  do until eof(1)
   ' GET$ #1, 1, mask1 'mask not in file ???????
    mask =  rnd(1, 255)
    get$ #1, 1, data1
    decoded = decoded + chr$(asc(data1) xor mask)
  loop
  close #1
  ? decoded ,, "After decode."

  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
Reply


Messages In This Thread
RE: Making text unreadable, 1 sample code works, 2 do not work - by Dale Yarker - 23.01.2026, 14:06

Forum Jump:


Users browsing this thread: 1 Guest(s)