fork download
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my $pass = '(6\!_I\=";I4U( '
  6. my $pass2 = decrypt($pass);
  7. print "Decrypted: $pass2\n";
  8. $pass2 = decrypt($pass2);
  9. print "Decrypted: $pass2\n";
  10. if ($pass ne $pass2) {
  11. print "Test Failed!\n";
  12. exit(-1);
  13. }
  14.  
  15. sub encrypt {
  16. my $pass = shift;
  17. my $strTarget = XORString($pass);
  18. $strTarget = StringToHex($strTarget);
  19. return $strTarget;
  20. }
  21.  
  22. sub decrypt {
  23. my $pass = shift;
  24. my $strTarget = HexToString($pass);
  25. $strTarget = XORString($strTarget);
  26. return $strTarget;
  27. }
  28.  
  29. sub GetKeyForLength {
  30. my $nLength = shift;
  31. my $nKeyLen = length '4p0L@r1$';
  32. my $nRepeats = $nLength / $nKeyLen + 1;
  33. my $strResult = '4p0L@r1$' x $nRepeats;
  34. return substr $strResult, 0, $nLength;
  35. }
  36.  
  37. sub HexToString {
  38. my $str = shift;
  39. my @bytes;
  40.  
  41. while ($str =~ s/^(..)//) {
  42. my $b = eval("0x$1");
  43. push @bytes, chr sprintf("%d", $b);
  44. }
  45. return join "", @bytes;
  46. }
  47.  
  48. sub XORString {
  49. my $strTarget = shift;
  50. my $nTargetLen = length $strTarget;
  51. my $strPaddedKey = GetKeyForLength($nTargetLen);
  52. my @bytes;
  53.  
  54. while ($strTarget) {
  55. my $b = (chop $strTarget) ^ (chop $strPaddedKey);
  56. unshift @bytes, $b;
  57. }
  58. return join "", @bytes;
  59. }
  60.  
  61. sub StringToHex {
  62. my $strInput = shift;
  63. my $hex = "";
  64. for my $ch (split //, $strInput) {
  65. $hex .= sprintf("%02x", ord $ch);
  66. }
  67. return $hex;
  68. }
  69.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
===SORRY!===
Unable to find module 'strict' in the @*INC directories.
(@*INC contains:
  /home/GJauEQ/.perl6/lib
  /usr/lib/parrot/2.7.0/languages/perl6/lib
  .)
stdout
Standard output is empty