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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:59:36+00:00 2026-05-31T17:59:36+00:00

I am creating an encryption algorithm and is to XOR two strings. While I

  • 0

I am creating an encryption algorithm and is to XOR two strings. While I know how to XOR the two strings the problem is the length. I have two byte arrays one for the plain text which is of a variable size and then the key which is of 56 bytes lets say. What I want to know is what is the correct method of XORing the two strings. Concatenate them into one String in Binary and XOR the two values? Have each byte array position XOR a concatenated Binary value of the key and such. Any help is greatly appreciated.

Regards,
Milinda

  • 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-31T17:59:37+00:00Added an answer on May 31, 2026 at 5:59 pm

    To encode just move through the array of bytes from the plain text, repeating the key as necessary with the mod % operator. Be sure to use the same character set at both ends.
    Conceptually we’re repeating the key like this, ignoring encoding.

    hello world, there are sheep
    secretsecretsecretsecretsecr
    

    Encrypt

    String plainText = "hello world, there are sheep";
    Charset charSet = Charset.forName("UTF-8");
    byte[] plainBytes = plainText.getBytes(charSet);
    String key = "secret";
    byte[] keyBytes = key.getBytes(charSet);
    
    byte[] cipherBytes = new byte[plainBytes.length];
    for (int i = 0; i < plainBytes.length; i++) {
    
        cipherBytes[i] = (byte) (plainBytes[i] ^ keyBytes[i
                % keyBytes.length]);
    }
    String cipherText = new String(cipherBytes, charSet);
    System.out.println(cipherText);
    

    To decrypt just reverse the process.

    // decode
    for (int i = 0; i < cipherBytes.length; i++) {
    
        plainBytes[i] = (byte) (cipherBytes[i] ^ keyBytes[i
                % keyBytes.length]);
    }
    plainText = new String(plainBytes, charSet); // <= make sure same charset both ends
    System.out.println(plainText);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inserted some data in table using encryption (encrypted by creating my own
I am using database in one of my application while creating database. I am
I have been doing some research on creating an encryption/decryption class for use in
I am creating a very basic encryption program using XOR to encrypt a user
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
When creating a web application, and lets say you have a User object denoting
I am creating an encryption scheme with AES in cbc mode with a 256-bit
per my question Aes Encryption... missing an important piece , I have now learned
I am creating a program that encrypts/hashs messages I have a list that contains

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.