Recent

Author Topic: Need any strings which available in runtime mode (encryption)  (Read 2055 times)

noszone

  • New Member
  • *
  • Posts: 46
Need any strings which available in runtime mode (encryption)
« on: September 15, 2021, 01:16:39 pm »
I need any constants or strings which is available during runtime. I need them in order to use as a salt(key) to a password function. Or any other suggestions?
Main requirement - thiese strings has to be available independent of OS or platform.
The encryption is quite simple (XOR), it's enough.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: Need any strings which available in runtime mode (encryption)
« Reply #1 on: September 15, 2021, 02:01:05 pm »
Hi noszone,

Could you please elaborate on the origin of such constants or strings?

Are they Environment Variables?
Are they constants you declare on a unit?
Are they command line params?

Cheers,
Gus
« Last Edit: September 15, 2021, 02:02:47 pm by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Need any strings which available in runtime mode (encryption)
« Reply #2 on: September 15, 2021, 04:01:29 pm »
> Main requirement - thiese strings has to be available independent of OS or platform.

I think most (if not all) of the string you are thinking of come from the environment and are very OS and platform dependent.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Need any strings which available in runtime mode (encryption)
« Reply #3 on: September 16, 2021, 01:00:29 am »

I can only think "Web page", even objective caml in Haiku should get that.
Try this maybe, click OK in the box and wait some seconds.
Code: Pascal  [Select][+][-]
  1.  
  2. program WebPageToText;
  3. {-Sg}
  4. uses
  5.   sysutils;
  6.  
  7.  function  system(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';
  8.  
  9.  type AOS=array of string;
  10.  var
  11.  g:ansistring;
  12. defaultstring:ansistring = 'https://forum.lazarus.freepascal.org/index.php/topic,56287.0.html';     // set as default
  13.  kill:integer=1;
  14.  i:int32;
  15.  a:AOS;
  16.  
  17.  procedure savefile(fname:string ;text:ansistring;killflag:integer);
  18.  label
  19.  kill;
  20. Var
  21.  T:TextFile;
  22. begin
  23. if killflag<>0 then goto kill;
  24.    AssignFile(T,fname);
  25.    {$I-}
  26.    try
  27.    Rewrite(T);
  28.    Writeln(T,text);
  29.    finally
  30.    CloseFile(T);
  31.    {$I+}
  32.    end;
  33.    kill:
  34.   if killflag<>0 then erase(T);
  35. end;
  36.  
  37. procedure runscript(filename:ansiString);
  38. begin
  39.   system(pchar('cscript.exe /Nologo '+ filename) );
  40. End;
  41.  
  42. procedure loadfiletoarray(filename:ansistring;var a:aos);
  43.    var
  44.     ret:ansistring;
  45.     f:textfile;
  46.     counter:integer;
  47.    begin
  48.    if (fileexists(filename)=false) then
  49.    begin
  50.    writeln(filename,'  not found');
  51.    exit;
  52.    end;
  53.    counter:=0;
  54.     AssignFile(f,filename);
  55.     reset(f);
  56.     while not eof(f) do
  57.     begin
  58.     counter:=counter+1;
  59.       readln(f, ret);
  60.     end;
  61.     setlength(a,counter);
  62.     reset(f);
  63.     counter:=0;
  64.      while not eof(f) do
  65.     begin
  66.     counter:=counter+1;
  67.       readln(f, a[counter]);
  68.     end;
  69.     CloseFile(f);
  70.    end; {loadfile}
  71.  
  72. begin
  73. g:=g+ 'Const TriStateTrue = -1 '+chr(10);
  74. g:=g+ 'URL = InputBox("Enter (or paste) the URL to extract the Code "&vbcr&vbcr&_'+chr(10);
  75. g:=g+ '"Exemple ""https://www.freebasic.net""","Extraction of Source text and html  ","'+defaultstring+'")'+chr(10);
  76. g:=g+ 'If URL = "" Then WScript.Quit'+chr(10);
  77. g:=g+ 'Titre = "Extraction du Code Source de " & URL'+chr(10);
  78. g:=g+ 'Set ie = CreateObject("InternetExplorer.Application")'+chr(10);
  79. g:=g+ 'Set objFSO = CreateObject("Scripting.FileSystemObject")'+chr(10);
  80. g:=g+ 'ie.Navigate(URL)'+chr(10);
  81. g:=g+ 'ie.Visible=false'+chr(10);
  82. g:=g+ 'DO WHILE ie.busy'+chr(10);
  83. g:=g+ 'LOOP'+chr(10);
  84. g:=g+ 'DataHTML = ie.document.documentElement.innerHTML'+chr(10);
  85. g:=g+ 'DataTxt = ie.document.documentElement.innerText'+chr(10);
  86. g:=g+ 'strFileHTML = "CodeSourceHTML.txt"'+chr(10);
  87. g:=g+ 'strFileTxt = "CodeSourceTxt.txt"'+chr(10);
  88. g:=g+ 'Set objHTMLFile = objFSO.OpenTextFile(strFileHTML,2,True, TriStateTrue)'+chr(10);
  89. g:=g+ 'objHTMLFile.WriteLine(DataHTML)'+chr(10);
  90. g:=g+ 'objHTMLFile.Close'+chr(10);
  91. g:=g+ 'Set objTxtFile = objFSO.OpenTextFile(strFileTxt,2,True, TriStateTrue)'+chr(10);
  92. g:=g+ 'objTxtFile.WriteLine(DataTxt)'+chr(10);
  93. g:=g+ 'objTxtFile.Close'+chr(10);
  94. g:=g+ 'ie.Quit'+chr(10);
  95. g:=g+ 'Set ie=Nothing'+chr(10);
  96. g:=g+ ' Ouvrir(strFileHTML)'+chr(10);
  97. g:=g+ ' Ouvrir(strFileTxt)'+chr(10);
  98. g:=g+ 'wscript.Quit'+chr(10);
  99. g:=g+ 'Function Ouvrir(File)'+chr(10);
  100. g:=g+ '    Set ws=CreateObject("wscript.shell")'+chr(10);
  101. g:=g+ '    ws.run "Notepad.exe "& File,1,False'+chr(10);
  102. g:=g+ 'end Function'+chr(10);
  103.  
  104.  
  105.  
  106. savefile('script.vbs',g,0) ;
  107. runscript('script.vbs');
  108.  
  109. writeln('Press enter to continue . . .');
  110. readln;
  111. writeln;
  112.  
  113. loadfiletoarray('codesourcetxt.txt',a);
  114. writeln('array size ',high(a));
  115. //for i:=low(a) to high(a)  do writeln(i,'   ',a[i]);
  116.  
  117. writeln('A string (plucked from the array) =   ','"',a[59],'"');
  118. writeln;
  119. writeln('Press enter to finish');
  120. readln;
  121.  
  122.  savefile('script.vbs','',kill);
  123.  
  124.  
  125.  
  126. end.
  127.  
  128.  
  129.  
(This web page)
version 3.2.2 64 bits win 10


dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Need any strings which available in runtime mode (encryption)
« Reply #4 on: September 16, 2021, 03:42:51 am »
Hmm, its not clear to me if the OP wants a random string or wants to get the same string every time he/she looks.  If its random, why not use GUID ? Dead easy.

Code: Pascal  [Select][+][-]
  1. var
  2.     GUID : TGUID;
  3. begin
  4.     CreateGUID(GUID);
  5.     result := copy(GUIDToString(GUID), 2, 36);      // it arrives here wrapped in {}  

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

noszone

  • New Member
  • *
  • Posts: 46
Re: Need any strings which available in runtime mode (encryption)
« Reply #5 on: September 16, 2021, 06:34:29 am »
Thanks, I will check if provided code will work a bit later. In general I need dedicated strings. The one idea is to take a Windows Registry string, but hey, isn't there any simpler way? Like some constant, error strings in executable, etc..

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Need any strings which available in runtime mode (encryption)
« Reply #6 on: September 16, 2021, 03:51:32 pm »
You can simply use a pseudo random number generator with a fixed seed. This can generate you arbitrary long and arbitrary many bitstrings and doesn't cost much memory like hardcoding strings

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Need any strings which available in runtime mode (encryption)
« Reply #7 on: September 16, 2021, 03:56:58 pm »
Thanks, I will check if provided code will work a bit later. In general I need dedicated strings. The one idea is to take a Windows Registry string, but hey, isn't there any simpler way? Like some constant, error strings in executable, etc..

WHAT ARE YOU TRYING TO DO? Get a fingerprint of the system so that you know somebody hasn't moved your binary? Get a non-constant string to seed encryption? Generate a per-user key that can be used multiple times? You're being hopelessly vague, and as such nobody here is really able to give you good advice... worse, you might misinterpret somebody's advice and try to use it inappropriately.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018