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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:29:45+00:00 2026-05-27T04:29:45+00:00

So today I was doing what I sometimes do which is just program stuff

  • 0

So today I was doing what I sometimes do which is just program stuff for fun, and I decided to make my own encryption method. I think it’s a basic stream cipher. The thing is I know next to nothing about cryptography, so I don’t know how secure it is.

Here is the method (implemented in PHP)

public function encrypt($data)
{
    $keylen = sizeof($this->key);
    $i=0;
    $current = 0; //Current offset for the cipher
    $ascii = utf8_decode($data);
    $output = "";
    for ($i=0;$i<strlen($ascii);$i++)
    {
        //Moves the cipher offset based on the key and the value of what is being
        //encrypted
        $current += ord($ascii[$i]) + $this->key[$i % $keylen];
        $current = $current % 256;
        $output .= chr($this->cipher[$current]);
        //Moves the cipher offset to the value of the subsequent cipher key
        $current = $this->cipher[($current+1)%256];
    }
    return $output;
}

Explanations

$this->cipher a preshuffled array of all integer values from 0-255, each only showing once. (Effectively a one to one function, without any kind of pattern)

$this->key a 512 byte random key (Unlike the cipher array may contain repeated values)

The cipher and key used for decryption must be the same as the one used for encryption obviously to retrieve the plaintext.

Decrypt method

public function decrypt($data)
{
    $keylen = sizeof($this->key);
    $i=0;
    $offset = 0;
    $output = "";
    for ($i=0;$i<strlen($data);$i++)
    {
        $current = $this->r_cipher[ord($data[$i])];
        //Calculates the offset for the next iteration
        $next = $this->cipher[($current+1)%256];
        //Subtracts the calculated offset and key value
        $current -= $offset + $this->key[$i % $keylen];
        //Makes sure value is between 0 and 255
        $current = ($current+512)%256; 
        $output .= chr($current);
        $offset = $next;
    }
    return utf8_encode($output);
}

r_cipher is just the inverse function to the cipher function

http://pastebin.com/KbvHZnD1 Examples of the algorithm in use, gives the sample key and cipher as well as several examples

  • 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-27T04:29:45+00:00Added an answer on May 27, 2026 at 4:29 am

    Since it’s a streamy cypher, key reuse is probably very problematic.


    $output .= chr($this->cipher[$current]);
    $current = $this->cipher[($current+1)%256];
    

    This implies that the state of current after this character is simply a permutation of the output byte.

    So whenever one looks at two values that are a multiple of 512 bytes apart, have the same preceding output, and the input at that position is the same the output will be the same. That’s a clear deviation from ideal cypher properties.


    If you encode all 256 get the content of cypher apart from an offset on the index. After this you’re reduced to a 512 byte caesar cypher.

    Combining these two weaknesses you get a full key recovery on a known plain-text of a few hundred kB.

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

Sidebar

Related Questions

I've been doing lots of vector math stuff and wrote my own template for
How you doing today? Wish you all good. By the way, here is my
Guys; How are you doing today? I have to create a dll project on
today I got confused when doing a couple of <%=Html.LabelFor(m=>m.MyProperty)%> in ASP.NET MVC 2
When doing some web maintenance today, I noticed a strange new folder on my
I came across a strange behaviour when doing some regular expressions in JavaScript today
I was working on my advanced calculus homework today and we're doing some iteration
today i was doing some java script coding, in that i need some images
I know just enough about SQL tuning to get myself in trouble. Today I
I was doing some testing and debugging of my Iphone app today and encountered

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.