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

  • Home
  • SEARCH
  • 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 939321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:46:17+00:00 2026-05-15T21:46:17+00:00

I have been using the encryption class of codeigniter (PHP framework) for a while

  • 0

I have been using the encryption class of codeigniter (PHP framework) for a while and need to convert these functions in PHP to C#.
This is so that my C# application can decrypt the data on my website database and vise versa.

The problem is that I have recently started with C# so don’t really know the function names that would do the same as PHP.

If I can convert these 3 functions, I’m sure I would be able to do their opposite 3 functions myself as they use near enough the same functions.

Note: Please don’t try to use these functions other than to play around – they are not strong cryptography (in fact, the method used could even be broken before the invention of computers).

/**
 * XOR Encode
 *
 * Takes a plain-text string and key as input and generates an
 * encoded bit-string using XOR
 *
 * @access  private
 * @param   string
 * @param   string
 * @return  string
 */
function _xor_encode($string, $key)
{
    $rand = '';
    while (strlen($rand) < 32)
    {
        $rand .= mt_rand(0, mt_getrandmax());
    }

    $rand = $this->hash($rand);

    $enc = '';
    for ($i = 0; $i < strlen($string); $i++)
    {           
        $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1));
    }

    return $this->_xor_merge($enc, $key);
}

    /**
 * XOR key + string Combiner
 *
 * Takes a string and key as input and computes the difference using XOR
 *
 * @access  private
 * @param   string
 * @param   string
 * @return  string
 */
function _xor_merge($string, $key)
{
    $hash = $this->hash($key);
    $str = '';
    for ($i = 0; $i < strlen($string); $i++)
    {
        $str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1);
    }

    return $str;
}

/**
 * Adds permuted noise to the IV + encrypted data to protect
 * against Man-in-the-middle attacks on CBC mode ciphers
 * http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
 *
 * Function description
 *
 * @access  private
 * @param   string
 * @param   string
 * @return  string
 */
function _add_cipher_noise($data, $key)
{
    $keyhash = $this->hash($key);
    $keylen = strlen($keyhash);
    $str = '';

    for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
    {
        if ($j >= $keylen)
        {
            $j = 0;
        }

        $str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256);
    }

    return $str;
}


/**
 * Hash encode a string
 *
 * @access  public
 * @param   string
 * @return  string
 */ 
function hash($str)
{
    return ($this->_hash_type == 'sha1') ? sha1($str) : md5($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-15T21:46:17+00:00Added an answer on May 15, 2026 at 9:46 pm

    i’ll give you small hint. all C-like constructs and operators go as is, other:

    • strlen – String.Length
    • substr – String.Substring
    • . – +, .= – +=
    • chr(c) – (byte)c
    • ord(i) – (char)i
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Flask for some time now and I am really enjoying
I have been tasked with decrypting a file in Java that has been encrypted
I don't have a good knowledge of SSL principles, but just want the encryption
I know, I know, similar questions have been asked millions and billions of times
I have a reasonable number of records in an Azure Table that I'm attempting
I'm looking to store some fairly sensitive data using PHP and MySQL and will
I have looked through the whole set of Oracle Database 11g Release 2 (11.2)
So assume you have two clients, C1 and C2, each client has a GUID
I've been trying to debug my code for the past few hours and I
I am doing a security review on a system. From one part of the

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.