Maybe this will help.
The key is a number, any number that fits in 32 bits.
Cycles is the number of cycles to repeat the encryption.
You can send the key and optionally the number of cycles per sms.
The other side needs a small executable that does the decryption
or you can build it in the application:
function Crypt(const Data:TBytes;Key:Cardinal;Cycles:Cardinal=1):TBytes;inline;
var
i,j:integer;
begin
Result := [];
Setlength(Result, Length(Data));
For i:= 0 to Pred(Cycles) do
for j:= 0 to high(Data) do
begin
{ this is an lcg type prng, actually Delphi's }
Key := Key * 134775813 + 1;
Result[j] := Data[j] xor (Key * 256 shr 32);
end;
end;
// more secure
function CryptXos(const Data:TBytes;Key:Cardinal;Cycles:Cardinal=1):TBytes;inline;
var
i,j:integer;
begin
Result := [];
Setlength(Result, Length(Data));
For i:= 0 to Pred(Cycles) do
for j:= 0 to high(Data) do
begin
key := key xor(key shl 13);
key := key shr 17;
key := key xor (key shl 5);
result[j] := key;
end;
end;
Just put your code in a TBytes.
Then send the key and optionally the number of cycles per sms and the encrypted data over internet.
The other side will be able to decrypt by calling the same function with the key and optionally the cycles from the sms.
trunk
FPC 3.3.1-17789-g5952c5452b [2025/04/13] for x86_64 - Win64
tkUString
Enter your pincode:
12345
Encrypt: This is thè téxt to êncrypt/decrypt Ä.
Equivalent in bytes:
54 124 203 3 40 144 78 162 163 174 216 148 90 136 0 183 251 243 162 137 182 240 141 68 210 224 25 153 247 166 119 222 221 127 169 180 109 253
Decrypt: 䨶赼埋ᐃ劐쥎涢첣ෘ澔띚䢈က₷䟻훳ಢ쮉ຶ㗰튍迒쓠ꮙ䆦ꭷߞዝ챿ꖩ▴ㇽ
Result: This is thè téxt to êncrypt/decrypt Ä.
If required I can easily adapt it to use an even more advanced (RSA) encryption but the XOS version is already very secure.
In effect the key is the random seed.
I also have a stream version.
This encryption is symmetric, so the same function encrypts and decrypts.
For normal people this is impossible to decrypt if you don't know the key and the cycles, it is way more advanced than simple XOR.
Let me know if this fits your requirements.