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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:10:31+00:00 2026-06-13T21:10:31+00:00

I have simple encrypt function which takes string, convert it to bytes, xor it

  • 0

I have simple encrypt function which takes string, convert it to bytes, xor it and apply base64.

JAVA:

String key = "1234";
public String encrypt(String plainText) throws Exception {

    byte [] input = plainText.getBytes("UTF8");
    byte [] output = new byte[input.length];
    for(int i=0; i<input.length; i++)
        output[i] = ((byte)(input[i] ^ key.charAt(i % key.length())));

    String utf8 = new String(output);
    return Utils.encode(utf8); 
}

Then I save it to a file and open it in another application in C# using this decrypting method:

C#:

string key="1234";
public string Decrypt(string CipherText)
{
    var decoded = System.Convert.FromBase64String(CipherText);
    var dexored = xor(decoded, key);
    return Encoding.UTF8.GetString(dexored);
}

byte[] xor(byte[] text, string key)
{
    byte[] res = new byte[text.Length];

    for (int c = 0; c < text.Length; c++)
    {
        res[c] = (byte)((uint)text[c] ^ (uint)key[c % key.Length]);
    }

    return res;
}

Problem is that accented characters like ěščřžýáí fail to decode.

Do you have any idea how to determine from which part the problem comes from or how to find it out? Looks to me that it has something to do with UTF-8.

I don’t need suggestions for a better encryption. I have already working AES but I want to switch to xored base64 due to performance issues.

Thank you.

  • 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-13T21:10:33+00:00Added an answer on June 13, 2026 at 9:10 pm

    This is the problem:

    String utf8 = new String(output);
    return Utils.encode(utf8); 
    

    You should be using base64 here on output, rather than constructing a string out of the now-not-really-text data. It’s possible that Utils.encode performs base64 encoding, having converted the input string back to byte for some reason – but fundamentally you shouldn’t be constructing a string with your encrypted bytes using the String constructor.

    If your Utils class has an encode(byte[]) method – and if that really does base64-encode the data (it’s very frustrating to only have half of the code you’re using) then you can just use:

    return Utils.encode(output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an encryption function which encrypts a simple value and stores it
I have a very simple encryption class using tripleDES to encrypt the query string
I'd like to have a super simple / fast encrypt/decrypt function for non-critical pieces
I have this simple function for encrypting strings via Vigenère in Java. I omitted
I have simple class with width and height member fields which define number of
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have given a task in which I need to encrypt an user's ID
I have already read Using Java to encrypt integers and Encrypting with DES Using
i have a simple Jquery code which is for sending $.ajax request and passing
I need fast and simple way to encrypt/decrypt a lot of String data. I

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.