Advertisement
mixster

R0b0t1

Jul 21st, 2008
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 9.19 KB | None | 0 0
  1. program Encryption2;
  2. var
  3.   chars: array of Char;
  4. procedure StrToIntArr(input: string; var output: TIntegerArray);
  5. var
  6.   sc: Integer;
  7.   cc: Integer;
  8.  
  9. begin
  10.   SetArrayLength(output, 0);
  11.   SetArrayLength(output, Length(input));
  12.  
  13.   for sc := 1 to Length(input) do
  14.     for cc := 0 to High(chars) do
  15.       if input[sc] = chars[cc] then
  16.         output[sc - 1] := cc;
  17. end;
  18.  
  19. procedure IntArrToStr(input: TIntegerArray; var output: string);
  20. var
  21.   sc: Integer;
  22.  
  23. begin
  24.   output := '';
  25.   for sc := 0 to High(input) do
  26.   begin
  27.     if input[sc] > High(input) then
  28.       input[sc] := input[sc] mod (High(chars) + 1)
  29.     else if input[sc] < 0 then
  30.       input[sc] := (((High(chars) + 1) * 10) - input[sc]) mod (High(chars) + 1);
  31.     output := output + chars[input[sc]];
  32.   end;
  33. end;
  34.  
  35. procedure SToIA(input: string; var output: TIntegerArray);
  36. var
  37.   sc: Integer;
  38.  
  39. begin
  40.   SetArrayLength(output, 0);
  41.   SetArrayLength(output, Length(input));
  42.  
  43.   for sc := 1 to Length(input) do
  44.     output[sc - 1] := Ord(input[sc]);
  45. end;
  46.  
  47. procedure IAToS(input: TIntegerArray; var output: string);
  48. var
  49.   sc: Integer;
  50.  
  51. begin
  52.   output := '';
  53.   for sc := 0 to High(input) do
  54.     output := output + Chr(input[sc]);
  55. end;
  56.  
  57. procedure EncryptOffset(input: string; offset: Integer; var output: string);
  58. var
  59.   iTIA: TIntegerArray; // 'InputTIntegerArray' - holds the integer version of the string
  60.   sc: Integer; // 'StringChar' - the char of the input/output string it's on
  61.  
  62. begin
  63.   output := ''; // Reset output
  64.   StrToIntArr(input, iTIA); // Change to TIntegerArray
  65.  
  66.   for sc := 0 to High(iTIA) do // Loop through all char's
  67.     IncEx(iTIA[sc], offset); // Increase them by 'offset' to change their value
  68.  
  69.   IntArrToStr(iTIA, output); // Convert it back
  70. end;
  71.  
  72. procedure DecryptOffset(input: string);
  73. var
  74.   cc: Integer; // 'CharChar' - the char currently being added to offset
  75.   s: string; // Simple string holder
  76.  
  77. begin
  78.   for cc := 0 to High(chars) do // Loop through every char available
  79.   begin
  80.     EncryptOffset(input, cc, s); // Use the encryption to decrypt it due to the looping nature of it - genius, eh?
  81.     Writeln(s); // Write it out since we have no idea of the content, it will have to be browsed through to find the right one
  82.   end;
  83. end;
  84.  
  85. procedure EncryptSplit(input: string; var output: string);
  86. var
  87.   iTIA: TIntegerArray; // 'InputTintegerArray' - holds the integer version of the input string
  88.   oTIA: TIntegerArray; // 'OutputTintegerArray' - holds the integer version of the output string
  89.   sc: Integer; // 'StringChar' - the char of the input string currently being decrypted
  90.  
  91. begin
  92.   output := ''; // Reset output
  93.   StrToIntArr(input, iTIA);
  94.   SetArrayLength(oTIA, (High(iTIA) + 1) * 2); // Double the length as each char is split into 2, so takes up twice as much space
  95.  
  96.   for sc := 0 to High(iTIA) do // Loop through all of the characters in the integer string
  97.   begin
  98.     oTIA[(sc * 2) + 1] := Random(iTIA[sc]); // Set the second of each pair to a random value below the actual
  99.     oTIA[sc * 2] := iTIA[sc] - oTIA[(sc * 2) + 1]; // Subtract the random char from the actual char so that it can be decrypted by combining
  100.   end;
  101.  
  102.   IntArrToStr(oTIA, output); // Convert back to string
  103. end;
  104.  
  105. procedure DecryptSplit(input: string; var output: string);
  106. var
  107.   iTIA: TIntegerArray; // 'InputTintegerArray' - holds the integer version of the input string
  108.   oTIA: TIntegerArray; // 'OutputTintegerArray' - holds the integer version of the output string
  109.   sc: Integer; // 'StringChar' - the char of the input string currently being decrypted
  110.  
  111. begin
  112.   output := ''; // Reset output
  113.   StrToIntArr(input, iTIA); // Convert input to integer array
  114.   SetArrayLength(oTIA, (High(iTIA) + 1) div 2); // Half the length as each pair of chars is combined, so takes up half as much space
  115.  
  116.   for sc := 0 to High(oTIA) do // Loop through all of the characters in the integer string
  117.     oTIA[sc] := iTIA[(sc * 2) + 1] + iTIA[sc * 2]; // Simply add them together
  118.  
  119.   IntArrToStr(oTIA, output); // Convert back to string
  120. end;
  121.  
  122. procedure EncryptMD5(input: string; var output: string);
  123. begin
  124.   output := ''; // Reset output
  125.   output := MD5(input); // Convert it to MD5 hash
  126. end;
  127.  
  128. // Currently doesn't work fully but very close to
  129. procedure DecryptMD5(input: string; var output: TStringArray);
  130. var
  131.   pl: Integer;
  132.   s: string;
  133.   i: Int64;
  134.   pli: Integer;
  135.  
  136. begin
  137.   while true do
  138.   begin
  139.     Inc(pl); // Used to make it an infite for loop
  140.     SetLength(s, pl); // Change the length of 's' to current attempting length
  141.     while i <= Round(Pow(High(chars) + 1, pl)) - 1 do // Int64's don't work in for loops, so replaced with a while
  142.     begin
  143.       for pli := 1 to pl do // 'pli' refers to current char it's on, so runs through all of them
  144.         s[pli] := chars[Floor(i div Pow(High(chars) + 1, pli - 1)) mod (High(chars) + 1)]; // Very complicated - unexplainable possibly
  145.       if MD5(s) = input then // Check to see if the made pass collides
  146.       begin
  147.         SetArrayLength(output, High(output) + 2); // Increase output array
  148.         output[High(output)] := s; // Add the collision on
  149.         Writeln(output[High(output)]); // Write it out
  150.         if not StrToBoolDef(Readln('Continue?'), False) then // Check to see if it should continue
  151.           Exit; // Exit if they choose not to continue
  152.       end;
  153.       if i mod 121212 = 0 then // Write out current string and what it's on every 121212 string combonations
  154.         Writeln('Another 121,212 (' + IntToStr(i) + ') - ' + s + '...');
  155.       i := i + 1; // Increase 'i', not Inc as it doesn't work with 'i'
  156.     end;
  157.   end;
  158. end;
  159.  
  160. procedure EncryptKey(input: string; key: string; var output: string);
  161. var
  162.   sc: Integer; // 'StringChar' - the char of the input string currently being encrypted
  163.  
  164. begin
  165.   output := input; // We adjust the output which will be the same length
  166.  
  167.   for sc := 1 to Length(input) do // Run through all the chars
  168.         output[sc] := Chr(Ord(input[sc]) + Ord(key[(sc - 1) mod Length(key) + 1])); // Change the char to char+key using mod to loop it around
  169. end;
  170.  
  171. procedure DecryptKey(input: string; matchText: string; var output: string);
  172. var
  173.   s: string; // Stores the current key
  174.   sc, si, ei: Integer; // 'StringChar' - char of the string currently on, 'StartInt' - the ascii char to start on, 'EndInt' - the ascii char to end on
  175. begin
  176.   si := 32; // Ascii value to start on
  177.   ei := 126; // " to end on
  178.   s := Chr(si) + Chr(si); // Set the key initially to 2 start char's
  179.   SetLength(output, Length(s)); // 'output' will be the same length as 'input', so set it to the same length
  180.   repeat // Loop that increments key length
  181.     repeat // Loop that increments char's
  182.       s[Length(s)] := Chr(Ord(s[Length(s)]) + 1); // Increase last char by 1 ascii value
  183.       for sc := 1 to Length(input) do // Loop through all char's of input
  184.         output[sc] := Chr(Ord(input[sc]) - Ord(s[(sc - 1) mod Length(s) + 1])); // Set the individual char's of output to input - current key, which loops with mod
  185.       if Pos(matchText, output) > 0 then // Checks to see if the matchText is there
  186.       begin
  187.         Writeln(s); // Writes out the key if it does
  188.         Exit; // and exits to stop it running
  189.       end;
  190.       for sc := 1 to Length(s) do // Loop through the entire key char's
  191.         if Ord(s[sc]) < ei then // If it is smaller than 'ei', break
  192.           Break; // because that means it doesn't need to increase key size
  193.       if sc = (Length(s) + 1) then // 'for' loops leave values 1 higher than the 'to' value, so this means 'key' needs to be increased in length
  194.         Break; // Break out of the char loop to the key increasing loop
  195.       for sc := Length(s) downto 2 do // Run through all the char's from last to first
  196.         if Ord(s[sc]) >= ei then // If it is bigger than 'ei'
  197.         begin
  198.           s[sc] := Chr(si); // Reset it to 'si'
  199.           s[sc-1] := Chr(Ord(s[sc-1]) + 1); // and increase the next char (reverse order) by 1
  200.         end;
  201.     until false // End char incrementing loop
  202.     s := s + Chr(si); // Add another char onto the end (I use 'si' char, but any can be used)
  203.     for sc := 1 to Length(s) do // Loop through all of the char's
  204.       s[sc] := Chr(si); // and reset them to 'si'
  205.   until false // End key length incrementing loop
  206. end;
  207.  
  208. procedure EncryptShrShl(input: string; var output: string);
  209. var
  210.   sc: Integer;
  211. begin
  212.   SetLength(output, Length(input));
  213.   for sc := 1 to Length(input) do
  214.     output[sc] := Chr(Ord(input[sc])shl 1);
  215. end;
  216.  
  217. procedure DecryptShrShl(input: string);
  218. var
  219.   sc, shift: Integer;
  220.   s: string;
  221. begin
  222.   SetLength(s, Length(input));
  223.   for shift := 1 to 3 do
  224.   begin
  225.     for sc := 1 to Length(input) do
  226.       s[sc] := Chr(Ord(input[sc])shr shift);
  227.     Writeln('R' + IntToStr(shift) + ':' + s);
  228.   end;
  229. end;
  230.  
  231. procedure EncryptIncrement(input: string; var output: string);
  232. var
  233.   sc: Integer;
  234.  
  235. begin
  236.   SetLength(output, Length(input));
  237.   for sc := 1 to Length(input) do
  238.     output[sc] := Chr(Ord(input[sc]) + sc);
  239. end;
  240.  
  241. procedure DecryptIncrement(input: string; var output:string);
  242. var
  243.   sc: Integer;
  244. begin
  245.   SetLength(output, Length(input));
  246.   for sc := 1 to Length(input) do
  247.     output[sc] := Chr(Ord(input[sc]) - sc);
  248. end;
  249.  
  250.  
  251. var
  252.   s: string;
  253.  
  254. begin
  255.   ClearDebug;
  256. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement