Decryption Is Not Working >>>

I've used this simple code that encrypts plain text. Then I tried to decrypt it using the same encrypting method but reversed in encryption section. There's a multiplication process that I don't know how to reverse it in the decryption code.

Here is the code:

procedure TForm1.Button1Click(Sender: TObject);
  s: String;
  count, ilength: Integer;
  s := edit1.Text;
  ilength := Length(s);
  FOR count := 1 to ilength do
    s[count] := chr(ord(s[count]) * 4 + 1); // Encoding
  Label1.caption := s;
  // Display encoded text
  // Decoding section
  // This will probably be placed in another procedure.
  FOR count := 1 to ilength do
    s[count] := chr(ord((s[count]) / 4) - 1);
    // Here I Get An Error ! Please Help Guys, Thanks


You are trying to perform integer division. In Delphi you do that with div. The / operator is for floating point division. Looking at the code, you are trying to reverse this calculation:

ord(s[count]) * 4 + 1

You reverse that like this:

(ord(s[count]) - 1) div 4

However, your algorithm will not work. Consider what happens when you encrypt 64 and 128. You multiply by 4 to get 256 and 512 respectively. Then add one to get 257 and 513. Then you store back to an 8 bit data type and lose the higher order bytes. And so both characters are encoded to the value 1.

I'm assuming that you are using 8 bit text. But if you are using 16 bit text, your algorithm still fails in an exactly analogous fashion. Your proposed algorithm is not reversible.

I urge you to find an off-the-shelf encryption algorithm rather than trying to write your own. Encryption is hard to get right.

Need Your Help

Deep comparison and getting values in angular

javascript angularjs underscore.js

I do not have time to create a fiddle right now, but will definetely do so tomorrow.

MYSQL Delete outliers for mulitiple products


I’m working with a large database and I’m trying to delete data outliers. I found this code from a previous question and I modified it to work with my database.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.