I'm trying to write this method that takes some parameters from my text editor, and encrypt the text. I got part of it written, but I'm stuck on the next bit.

I got the part where you convert the "key", but I just can't figure out what to do next.

import java.util.*;

public class Encryptor
{
	public String encryptText(String key, String text)
	{
		String finalResult = "";
		
		for (int i=0; i<key.length(); i++)
		{
			long convert = (long)key.charAt(i);
			convert *= 128;
			finalResult += convert;
		}
		
		Random randomNumGenerator = new Random(keyResult);
		String returnString = "";
		
		
		return returnString;
	}
}

I'm trying to write this method that takes some parameters from my text editor, and encrypt the text. I got part of it written, but I'm stuck on the next bit.

I got the part where you convert the "key", but I just can't figure out what to do next.

import java.util.*;

public class Encryptor
{
	public String encryptText(String key, String text)
	{
		String finalResult = "";
		
		for (int i=0; i<key.length(); i++)
		{
			long convert = (long)key.charAt(i);
			convert *= 128;
			finalResult += convert;
		}
		
		Random randomNumGenerator = new Random(keyResult);
		String returnString = "";
		
		
		return returnString;
	}
}

Hi,
Your post is not clear. What exactly are you trying to do. You want to encrypt text and for that you have a key, right. You can use XOR alogo to encrypt your text. If you are following a specific algorithm let me know. I am not able to understand where exactly you are stuck up ?

cheers,
aj.wh.ca

Ok, I got the first part which is where you get the "encryption key" from the user, and convert it to a long. The second part, is actually encrypting the text using the random class, and the new converted key as the seed. I'm not following any alogorithm, im trying to come up with my own.

Here's a short example of how to shift the text one letter over. I'm trying to do something similar to this, except using a key(the seed), and using random values.

public class CeaserCypher
{
	public String shiftOne(String text)
	{
		long convert = 0;
		String finalResult = "";
		
		for (int i=0; i<text.length(); i++)
		{
			convert = (long)text.charAt(i) +1;
			finalResult += (char)convert;
		}
		
		return finalResult;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.