Recent

Author Topic: Compare strange characters (decryption)  (Read 1003 times)

nikel

  • Full Member
  • ***
  • Posts: 218
Compare strange characters (decryption)
« on: December 05, 2023, 07:31:33 am »
Hello, I'm trying to decrypt password box input. I have this encrypted password in a file:

Code: Pascal  [Select][+][-]
  1. èåQ:÷¯U

But when I load the file into stringlist I'm getting:

Code: Pascal  [Select][+][-]
  1. ??Q:?U

How can I correctly load my file?
« Last Edit: December 05, 2023, 07:35:57 am by nikel »

cdbc

  • Hero Member
  • *****
  • Posts: 1661
    • http://www.cdbc.dk
Re: Compare strange characters (decryption)
« Reply #1 on: December 05, 2023, 07:52:09 am »
Hi
That looks like a codepage issue e.g.: cp1252 -> UTF8 can result in ?
Have a look in package LazUtils, more specifically in LazUTF8 et.al. (LConvEncoding etc.)
Regards Benny
« Last Edit: December 05, 2023, 07:53:46 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

nikel

  • Full Member
  • ***
  • Posts: 218
Re: Compare strange characters (decryption)
« Reply #2 on: December 05, 2023, 07:56:18 am »
Thank you for your reply. I'm already using UTF8:

Code: Pascal  [Select][+][-]
  1.   if (OpenDialog1.Execute) then
  2.   begin
  3.     try
  4.       ListOfImport.LoadFromFile(OpenDialog1.FileName, TEncoding.UTF8);
  5.     except
  6.       on E: Exception do
  7.         raise Exception.Create(E.ClassName + #13 + E.Message);
  8.     end;
  9.  
  10.   end;

cdbc

  • Hero Member
  • *****
  • Posts: 1661
    • http://www.cdbc.dk
Re: Compare strange characters (decryption)
« Reply #3 on: December 05, 2023, 12:02:48 pm »
Hi
Yup, but that doesn't help if your file on disc is cpiso8859-1, then your TEncoding.UTF8 will try to load it as UTF8 and that produces ? ? ?
Somewhere in lazutils there's a function "DetectCodepage" or "GuessCodepage/Encoding", which will try to find the right cp.
...or try something like this:
Code: Pascal  [Select][+][-]
  1. function ISO_8859_15ToUTF8(const s: string): string;
from LConvEncoding on the string when you have loaded it(without TEncoding.UTF8)...
Regards Benny
« Last Edit: December 05, 2023, 12:05:51 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

kwyan

  • New Member
  • *
  • Posts: 25
Re: Compare strange characters (decryption)
« Reply #4 on: December 05, 2023, 03:00:13 pm »
My understanding is your data is encrypted password. It means it not UTF8 characters. So you save these into file or read it to the program, you must keep on using cp1252.

cdbc

  • Hero Member
  • *****
  • Posts: 1661
    • http://www.cdbc.dk
Re: Compare strange characters (decryption)
« Reply #5 on: December 05, 2023, 05:03:52 pm »
Hi
@kwyan is right, if you load your data without TEncoding,UTF8, then they might be ok, but the LCL cannot display them...
Try to check the data on disc with a hex-editor/dump and compare to what you get loaded... in a plain string behind the scenes, NOT edit1.text  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

nikel

  • Full Member
  • ***
  • Posts: 218
Re: Compare strange characters (decryption)
« Reply #6 on: December 05, 2023, 11:33:21 pm »
Thanks for the replies. I'm working on it.

 

TinyPortal © 2005-2018