Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  135

•  TDictionary Custom Sort  3 317

•  Fast Watermark Sources  3 065

•  3D Designer  4 825

•  Sik Screen Capture  3 320

•  Patch Maker  3 535

•  Айболит (remote control)  3 637

•  ListBox Drag & Drop  2 996

•  Доска для игры Реверси  81 561

•  Графические эффекты  3 927

•  Рисование по маске  3 231

•  Перетаскивание изображений  2 613

•  Canvas Drawing  2 735

•  Рисование Луны  2 561

•  Поворот изображения  2 166

•  Рисование стержней  2 161

•  Paint on Shape  1 564

•  Генератор кроссвордов  2 226

•  Головоломка Paletto  1 764

•  Теорема Монжа об окружностях  2 215

•  Пазл Numbrix  1 682

•  Заборы и коммивояжеры  2 052

•  Игра HIP  1 279

•  Игра Go (Го)  1 225

•  Симулятор лифта  1 471

•  Программа укладки плитки  1 214

•  Генератор лабиринта  1 542

•  Проверка числового ввода  1 352

•  HEX View  1 490

•  Физический маятник  1 355

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Шифрование текста по ключевым числам



Оформил: DeeCo

{ 
 This two functions are used to encrypt and decrypt text. 
 Here's how to use it: 
 The four entries Key1, Key2, Key3 and Key4 are numbers 
 that can range from 1 to 120. In order to decrypt a text, 
 you must use the same numbers you used to encrypt the text. 
 No one that doesn't know what values were used on Key1, Key2, Key3 and Key4 
 will be able to decrypt your text! 
 Note that Key1*Key4 MUST be different than Key2*Key3. 
 If any Key is zero, or Key1*Key4 is equal to Key2*Key3, 
 the function will return ''. 
 In Brief: 
      Key1, Key2, Key3, Key4 : integer from range[1..120] 
      Key1*Key4  Key2*Key3 
}

 function Encrypt(Text : string; Key1, Key2, Key3, Key4 : Integer) : string;
 var
  BufS, Hexa, Hexa1, Hexa2 : string;
  BufI, BufI2, Sc, Sl, Num1, Num2, Num3, Num4, Res1, Res2, Res3, Res4 : Integer;
 begin
  Sl := Length(Text);
  Sc := 0;
  BufS := '';
  if (Key1 in [1 .. 120]) and (Key2 in [1 .. 120]) and (Key3 in [1 .. 120]) and (Key4 in [1 .. 120]) then
  begin
   BufI := Key1 * Key4;
   BufI2 := Key3 * Key2;
   BufI := BufI - BufI2;
   if BufI = 0 then
   begin
    Result := '';
    Exit;
   end;
  end
  else
  begin
   Result := '';
   Exit;
  end;
  repeat
   Inc(Sc);
   if Sc > Sl then Num1 := 0 else Num1 := Ord(Text[Sc]);
   Inc(Sc);
   if Sc > Sl then Num2 := 0 else Num2 := Ord(Text[Sc]);
   Inc(Sc);
   if Sc > Sl then Num3 := 0 else Num3 := Ord(Text[Sc]);
   Inc(sc);
   if Sc > Sl then Num4 := 0 else Num4 := Ord(Text[Sc]);
   Res1 := Num1 * Key1;
   BufI := Num2 * Key3;
   Res1 := Res1 + BufI;
   Res2 := Num1 * Key2;
   BufI := Num2 * Key4;
   Res2 := Res2 + BufI;
   Res3 := Num3 * Key1;
   BufI := Num4 * Key3;
   Res3 := Res3 + BufI;
   Res4 := Num3 * Key2;
   BufI := Num4 * Key4;
   Res4 := Res4 + BufI;
   for BufI := 1 to 4 do
   begin
    case BufI of
     1 : Hexa := IntToHex(Res1, 4);
     2 : Hexa := IntToHex(Res2, 4);
     3 : Hexa := IntToHex(Res3, 4);
     4 : Hexa := IntToHex(Res4, 4);
    end;
    Hexa1 := '$' + Hexa[1] + Hexa[2];
    Hexa2 := '$' + Hexa[3] + Hexa[4];
    if (Hexa1 = '$00') and (Hexa2 = '$00') then
    begin
     Hexa1 := '$FF';
     Hexa2 := '$FF';
    end;
    if Hexa1 = '$00' then Hexa1 := '$FE';
    if Hexa2 = '$00' then
    begin
     Hexa2 := Hexa1;
     Hexa1 := '$FD';
    end;
    BufS := BufS + Chr(StrToInt(Hexa1)) + Chr(StrToInt(Hexa2));
   end;
   until Sc >= Sl;
  Result := BufS;
 end;

 function Decrypt(Text : string; Key1, Key2, Key3, Key4 : Integer) : string;
 var
  BufS, Hexa1, Hexa2 : string;
  BufI, BufI2, Divzr, Sc, Sl, Num1, Num2, Num3, Num4, Res1, Res2, Res3, Res4 : Integer;
 begin
  Sl := Length(Text);
  Sc := 0;
  BufS := '';
  if (Key1 in [1 .. 120]) and (Key2 in [1 .. 120]) and (Key3 in [1 .. 120]) and (Key4 in [1 .. 120]) then
  begin
   Divzr := Key1 * Key4;
   BufI2 := Key3 * Key2;
   Divzr := Divzr - BufI2;
   if Divzr = 0 then
   begin
    Result := '';
    Exit;
   end;
  end
  else
  begin
   Result := '';
   Exit;
  end;
  repeat
   for BufI := 1 to 4 do
   begin
    Inc(Sc);
    Hexa1 := IntToHex(Ord(Text[Sc]), 2);
    Inc(Sc);
    Hexa2 := IntToHex(Ord(Text[Sc]), 2);
    if Hexa1 = 'FF' then
    begin
     Hexa1 := '00';
     Hexa2 := '00';
    end;
    if Hexa1 = 'FE' then Hexa1 := '00';
    if Hexa1 = 'FD' then
    begin
     Hexa1 := Hexa2;
     Hexa2 := '00';
    end;
    case BufI of
     1 : Res1 := StrToInt('$' + Hexa1 + Hexa2);
     2 : Res2 := StrToInt('$' + Hexa1 + Hexa2);
     3 : Res3 := StrToInt('$' + Hexa1 + Hexa2);
     4 : Res4 := StrToInt('$' + Hexa1 + Hexa2);
    end;
   end;
   BufI := Res1 * Key4;
   BufI2 := Res2 * Key3;
   Num1 := BufI - BufI2;
   Num1 := Num1 div Divzr;
   BufI := Res2 * Key1;
   BufI2 := Res1 * Key2;
   Num2 := BufI - BufI2;
   Num2 := Num2 div Divzr;
   BufI := Res3 * Key4;
   BufI2 := Res4 * Key3;
   Num3 := BufI - BufI2;
   Num3 := Num3 div Divzr;
   BufI := Res4 * Key1;
   BufI2 := Res3 * Key2;
   Num4 := BufI - BufI2;
   Num4 := Num4 div Divzr;
   BufS := BufS + Chr(Num1) + Chr(Num2) + Chr(Num3) + Chr(Num4);
   until Sc >= Sl;
  Result := BufS;
 end;




Похожие по теме исходники

Codeo (шифрование Виженера / Цезаря)

ENRUPT шифрование

RTEA шифрование

Vigenere Plus (шифрование Виженера)

 

ARIA шифрование

Crypton шифрование

Шифрование Aes, Des, Плейфер

RSA шифрование через OpenSSL

 



Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте