Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 275737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:48:47+00:00 2026-05-12T00:48:47+00:00

This was not written by me; it was written by someone who passed it

  • 0

This was not written by me; it was written by someone who passed it down to me. I lost contact with the author of the code. I have been using this code for a few years and just now realized this error. It seems that the letter sequence rkey1 messes up the output.

For example turkey1 outputs as decryption as tur79y1. This Perl code should output turkey1 and not tur79y1:

$String = "turkey1";
$e = &encode_escaped(&palace_encrypt($String));
$d = &palace_decrypt(&decode_escaped("'\"".$e."\"'"));
print $d."<br>\n";

KEY REMOVED BY OWNER


sub palace_decrypt
{
    local $lastchar = 0;
    local $rc = 0;
    local @bs;
    for($i=length($_[0])-1; $i>=0; $i--) {
        local $tmp = ord(substr($_[0], $i, 1));
        $bs[$i] = $tmp ^ $palace_key[$rc++] ^ $lastchar;
        $lastchar = $tmp ^ $palace_key[$rc++];
        }

    return join("", map { chr($_) } @bs);
}

sub decode_escaped
{
    $_[0] =~ m/\"(.*)\"/;
    local $str = $1;
    $str =~ s/\\\\/\0/g;
    $str =~ s/\\"/"/g;
    $str =~ s/\\(..)/pack("c",hex($1))/ge;
    $str =~ s/\0/\\/g;
    return $str;
}


sub palace_encrypt
{
    local $lastchar = 0;
    local $rc = 0;
    local @bs;
    for($i=length($_[0])-1; $i>=0; $i--) {
        local $b = ord(substr($_[0], $i, 1));
        $bs[$i] = $b ^ $palace_key[$rc++] ^ $lastchar;
        $lastchar = $bs[$i] ^ $palace_key[$rc++];
        }
    return join("", map { chr($_) } @bs);
}

sub encode_escaped
{
    local $str = $_[0];
    $str =~ s/\\/\\\\/g;
    $str =~ s/([^A-Za-z0-9\.\\])/sprintf("\\%2.2X", ord($1))/ge;

    return $str;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:48:48+00:00Added an answer on May 12, 2026 at 12:48 am

    Your problem is that your decode_escaped does not exactly undo what encode_escaped did. Replace it with the following and that should fix your problem.

    sub decode_escaped
    {
        $_[0] =~ m/\"(.*)\"/;
        local @str = split /(\\\\)/, $1;
        foreach (@str) {
            s/\\"/"/g;
            s/\\(..)/chr(hex($1))/ge;
            s/\\\\/\\/;
        }
        return join '', @str;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am obviously not a very good programmer. I have written this small
This not a programming question but Most of the programmers using Eclipse should have
I am still new to Python and have been reviewing the following code not
Yesterday I stumbled over this when I modified PHP code written by someone else.
I have some code written by someone else in which some functions take arguments
We've all been there. You have written some code and unit tests, the tests
I have some terribly written ASP.NET code that is just not working right (go
I'm editing some code which wasn't written by myself but someone who's no longer
i'm writing this: echo foo; echo \n; echo bar; and bar is not written
I have a matlab function written in an m-file. (it's not written by me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.