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 8555941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:14:24+00:00 2026-06-11T15:14:24+00:00

Im trying to encrypt data through a custom function i created… (based on base64)

  • 0

Im trying to encrypt data through a custom function i created… (based on base64)
The code works but to a degree… it gives random results (sometimes work and sometimes doesn’t).

<?php
set_time_limit(0);
class encryptor{
 function encrypt($data){
  $all = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?@,.&*()$; ";
  $chars = str_split($all, 1); // Split $all to array of single characters
  $text_chars = str_split($data, 1); // Split $data to array of single characters

  // Create array of unique results based on the characters from $all
  foreach($chars as $char){
   $array[$char] = md5(uniqid(rand(), true));
  }
  // Replace the input text with the results from $array 
  foreach($text_chars as $text_char){
   $data = str_replace($text_char,$array[$text_char], $data);
  }
  // Encode and compress $array as $solution
  $solution = gzcompress(base64_encode(json_encode($array)),9);
  // Return the encoded solution + Breaker + encoded and compressed input text
  return $solution."BREAKHERE".gzcompress(base64_encode($data),9);
 }
 function decrypt($data){
  // Break the encrypted code to two parts
  $exploded = explode('BREAKHERE', $data);
  // Decoding the contents
  $contents = base64_decode(gzuncompress($exploded[1]));
  // Decoding solution ($array)
  $solves = json_decode(base64_decode(gzuncompress($exploded[0])),true);
  $fliped = array_flip($solves);
  // Replace the encrypted data with the solution
  foreach($solves as $solve){
   $contents = str_replace($solve,$fliped[$solve], $contents);
  }
  return($contents); // Return decoded data
  }
 }

$text = "11 1";
$enc = new encryptor();
$encrypted = $enc->encrypt($text);
$decrypted = $enc->decrypt($encrypted);
echo $decrypted;
?>
  • 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-06-11T15:14:25+00:00Added an answer on June 11, 2026 at 3:14 pm

    Since its just for fun, this change appears to make it work:

    // Replace the input text with the results from $array
    $encrypted = '';
    foreach($text_chars as $text_char){
        //$data = str_replace($text_char,$array[$text_char], $data);
         $encrypted .= $array[$text_char];
    }
    

    Running str_replace in the loop results in substitutions of data that have been previously substituted.

    Aside from that, to make transport of the encrypted data easier, I’d change:

    return $solution."BREAKHERE".gzcompress(base64_encode($data),9);
    

    to:

    return base64_encode($solution."BREAKHERE".gzcompress($data,9);
    

    and then make the appropriate changes in the decryptor. The compress data can have null characters and non-printable characters so if you base64 encode the entire result you can pass it around more easily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Talking about javax.crypto.Cipher I was trying to encrypt data using Cipher.getInstance(RSA/None/NoPadding, BC) but I
I am trying to encrypt some data with the following code: public static byte[]
i am trying to use CCCrypt to encrypt my data , but something wrong
In a Rails 3.0 (Ruby 1.9.2) app I'm trying to encrypt some data using
I am trying to read from a file and encrypt the data using AES
I'm trying to measure how long it takes read then encrypt some data (independently).
I am trying encrypt and decrypt one column in table. My code is like
I am trying to encrypt and decrypt some simple text. But for some reason
I'm trying to encrypt an array of 256 bytes by using RSACryptoServiceProvider but I'm
I'm trying to encrypt and decrypt data using RSA in C#. I have 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.