PDA

View Full Version : $10 to finish this java program for me


kurosh
11-01-2005, 12:16 PM
All my funds are tied up right now, but I'm good for it. I'll send it in under a week. I'm almost done but I'm so tired that it'll take me hours to do the rest of it.

What I have so far is here (http://www.kurosh.org/test.txt). The encryption part is done. I just need the decryption part, which is partly finished. It's tougher than the encryption part. I think you'd have to loop through to find where the characters end. I was starting a loop to find where the spaces are.

This is the assignment:


Create a program that does the following:
1. Displays a short menu, asking the user to choose whether he/she wishes to encrypt data or decrypt data, or if he/she wishes to exit the program.

2. Prompt the user to enter an integer, which will be used as a private key.

3. If the user wishes to encrypt data, prompt the user to enter a phrase or sentence of text. On a character by character basis, convert that text into ASCII code and add the private key to each ASCII code. Print out the code as your convert it.

4. If the user wishes to decrypt data, prompt the user to enter code. On a code by code basis, subtract the private key and translate the resulting ASCII value into a letter, space, period or digit. Print out the text as you convert it.

Your program should redisplay the menu after each translation is finished. It should terminate only when the user selects the exit/quit option from the menu.

d10
11-01-2005, 12:19 PM
This encryption method is pretty weak.

jaydub
11-01-2005, 12:23 PM
1. this isn't encryption.
2. i normally don't get out of bed for less than $500 but for you, i'll do it for $100.

kurosh
11-01-2005, 12:26 PM
I realize it's not encryption. It's just an assignment I have to do. Is anyone trying this?

turnipmonster
11-01-2005, 12:28 PM
dude no one competent is going to do this for $10.

crunchy1
11-01-2005, 12:30 PM
[ QUOTE ]
I just need the decryption part, which is partly finished. It's tougher than the encryption part. I think you'd have to loop through to find where the characters end. I was starting a loop to find where the spaces are.

[/ QUOTE ]
Spaces are ASCII characters too. This isn't any harder than looping through each character of the "encrypted" string, "decrpyting" it and appending the result to the end of the result string.

You need to pay someone to do this for you? Sad.

kurosh
11-01-2005, 12:34 PM
It is harder because it's not just one character. The input is going to be something like 82 123 43 95 and it has to recognize the individual numbers.

kurosh
11-01-2005, 12:38 PM
I don't think it would take anyone competent more than 10 minutes max.

On another note, does anyone know how you would do this problem?

Write a Java program that accepts a string from a terminal and converts all the lowercase letters in the string to uppercase, and all the uppercase letters in the string to lowercase.

It's not arrays because we have not reached that chapter yet.

crunchy1
11-01-2005, 12:38 PM
[ QUOTE ]
It is harder because it's not just one character. The input is going to be something like 82 123 43 95 and it has to recognize the individual numbers.

[/ QUOTE ]
What the input is going to be is irrelevant - it should be able to be anything.

Work out a plan before you start thinking of the actual code. Here's a possible solution:

- You have an input string
--- Determine the total length of that string (accounting for ALL characters)
--- Create a loop that will execute a number of times equal to the length of the string
--- In each iteration of the loop
----- Find the character at the position in the string for that # iteration
----- Convert this character
----- Add the converted character to a second string that will be used to display the result

kurosh
11-01-2005, 12:42 PM
That won't work because it will convert individual digits into characters, not the entire number.

crunchy1
11-01-2005, 01:03 PM
[ QUOTE ]
That won't work because it will convert individual digits into characters, not the entire number.

[/ QUOTE ]
What you'll need to do is delimit the ASCII numbers that result from the encryption process. This way you'll have a method of reconstructing the string.

Yeti
11-01-2005, 01:07 PM
Dude, just give it up now. Java made me want to kill myself.

asofel
11-01-2005, 01:10 PM
[ QUOTE ]
That won't work because it will convert individual digits into characters, not the entire number.

[/ QUOTE ]

you should be able to cycle through and separate the numbers given where the spaces are, no?

krimson
11-01-2005, 01:11 PM
You don't need to do anything crazy here. There is something called the "String Tokenizer" (google it) that will help with reading the data. You can set it to use " " as a delimitter and it will parse your string for you.

You can probably find some University/College tutorials that demonstrate this farily easily.

icepick
11-01-2005, 01:13 PM
[ QUOTE ]
It is harder because it's not just one character. The input is going to be something like 82 123 43 95 and it has to recognize the individual numbers.

[/ QUOTE ]

This statement clearly shows you don't understand the assignment.

Start a loop.
Take the Nth character of your input string.
Convert that char to an ASCII number.
Add the key.
Convert back to a char.
Repeat untill done.

This is one line of perl.

crunchy1
11-01-2005, 01:14 PM
[ QUOTE ]
You don't need to do anything crazy here. There is something called the "String Tokenizer" (google it) that will help with reading the data.

[/ QUOTE ]
This is a good point that there is probably some class/method combination out there that will do what you need with minimal extra programming.

What you're missing (and what I didn't account for initially either) is that spaces are not an acceptable delimiter - because a space is a valid character in the input string. What you need to consider is that each character in the string is an individual character. Where we need to create and use a delimiter is in the encrypted string - so that we can recreate each individual character from the input string correctly.

kurosh
11-01-2005, 01:16 PM
Yes, daft told me about the string tokenizer which helped immensely. /images/graemlins/heart.gif daft. I'm done. No need for anything else. Thanks.

Jeffage
11-01-2005, 01:17 PM
Shouldn't be downing a bottle of hot sauce or something?

krimson
11-01-2005, 01:18 PM
I'm pretty Kurosh is trying to say that the input is of the format:

121 134 145 124 154 ...

and he's not sure how to read in the numbers.

krimson
11-01-2005, 01:19 PM
[ QUOTE ]
Shouldn't be downing a bottle of hot sauce or something?

[/ QUOTE ]
That's Crimson.

kurosh
11-01-2005, 01:20 PM
[ QUOTE ]
I'm pretty Kurosh is trying to say that the input is of the format:

121 134 145 124 154 ...

and he's not sure how to read in the numbers.

[/ QUOTE ]Yeah that was the main problem. I was starting to do a loop to find out where there are spaces and try to find a string method that would let me input what character range to use. String tokenizer saved me.

jba
11-01-2005, 01:21 PM
there are many bugs possible with char overflows and non numerics in the codes you are on your own.


StringTokenizer st = new StringTokenizer(s3, " ");
while(st.hasMoreTokens()) {
String token = st.nextToken();
int ascii = Integer.parseInt(token);
System.out.print(new Character((char) (ascii-key)));
}



test results
1 - Encrypt Data
2 - Decrypt Data
3 - Exit Program
1
Private Key?
1231458
Enter text for encryption
kurush is a dummy
1231565 1231575 1231572 1231575 1231573 1231562 1231490 1231563 1231573 1231490 1231555 1231490 1231558 1231575 1231567 1231567 1231579
1 - Encrypt Data
2 - Decrypt Data
3 - Exit Program
2
Private Key?
1231458
Enter code for decryption
1231565 1231575 1231572 1231575 1231573 1231562 1231490 1231563 1231573 1231490 1231555 1231490 1231558 1231575 1231567 1231567 1231579
kurush is a dummy
1 - Encrypt Data
2 - Decrypt Data
3 - Exit Program

d10
11-01-2005, 01:22 PM
I think spaces in the encrypted string are fine, because everything else should be integers. So a space in the original string would convert to 32 + whatever key was given. Although as a habit I do like to use something less common than a space. But anyways, I know very little about Java, but as others have mentioned, there must be some function out there (or whatever Java calls them) to split your encrypted strings at the spaces (in Perl, this would be pretty easy, @string=split(/\s/,$encrpytedstring), or something like that). Obviously the way you're doing it now isn't good because you're reading one character at a time, and a single integer may consist of more than one character. Also I'm not sure if what you're reading in is being interpreted as an integer or a character, which might give you problems.

I haven't touched a programming language of any kind in about 4 years, so if anyone disagrees with what I'm saying, you probably know better than I do.

icepick
11-01-2005, 01:25 PM
n/m

I wasn't considering the decrypt portion. Much harder than the encrypt part. I need to work on my reading comprehension.

kurosh
11-01-2005, 01:30 PM
Pretty much what I did:

StringTokenizer st = new StringTokenizer(s3);

while(st.hasMoreTokens())
{
s2 = st.nextToken();
a = Integer.parseInt(s2);
a = a-key;
y = (char) a;
System.out.print(y);
}

jon_1van
11-01-2005, 02:17 PM
Thats what you need to encrypt

Put the first block in the appropraite place.

Put the 2nd block inside the class{} but outside the main{}


//String theStringToEncrypt;
for(int i = 0 ; i < theStringToEncrypt.length() ; i++) {
char a = theStringToEncrypt.charAt(i);
System.out.println(convertChar(a));
}



public int convertChar(char aLetter , int theKey) {
int temp = (int) aLetter;
return (temp + theKey);
}

jon_1van
11-01-2005, 02:25 PM
[ QUOTE ]
Thats what you need to encrypt

Put the first block in the appropraite place.

Put the 2nd block inside the class{} but outside the main{}


//String theStringToEncrypt;
for(int i = 0 ; i < theStringToEncrypt.length() ; i++) {
char a = theStringToEncrypt.charAt(i);
System.out.println(convertChar(a));
}



public int convertChar(char aLetter , int theKey) {
int temp = (int) aLetter;
return (temp + theKey);
}

[/ QUOTE ]

If you use what I wrote appropraitely the result of encrypting "abcd efgh" (with the key = 0) should be ::

97
98
99
100
(whatever a space is in asci)
101
102
103
104

this is assuming that an 'a' when cast to an int is 97 (which it may not be because I don't have a table in front of me)

wonderwes
11-01-2005, 05:08 PM
This is why coding is one of the most painful professions to go into. I had to take about 5 coding classes of 3 different languages. All are a pain, and java by far is the most strict on syntax compared to all the other languages.

billymonk
11-01-2005, 05:30 PM
[ QUOTE ]

On another note, does anyone know how you would do this problem?

Write a Java program that accepts a string from a terminal and converts all the lowercase letters in the string to uppercase, and all the uppercase letters in the string to lowercase.

It's not arrays because we have not reached that chapter yet.

[/ QUOTE ]

Aren't their methods in the api to do this? I don't know them off the top of my head, but toLowerCase(), toUpperCase()?
Even without them, just find a relationship between lower case and upper case ASCII values and do it that way.

jaydub
11-01-2005, 05:31 PM
[ QUOTE ]
This is why coding is one of the most painful professions to go into. I had to take about 5 coding classes of 3 different languages. All are a pain, and java by far is the most strict on syntax compared to all the other languages.

[/ QUOTE ]

No. Someone who struggles with syntax is not going to have success as a programmer.

asofel
11-01-2005, 05:32 PM
[ QUOTE ]
[ QUOTE ]

On another note, does anyone know how you would do this problem?

Write a Java program that accepts a string from a terminal and converts all the lowercase letters in the string to uppercase, and all the uppercase letters in the string to lowercase.

It's not arrays because we have not reached that chapter yet.

[/ QUOTE ]

Aren't their methods in the api to do this? I don't know them off the top of my head, but toLowerCase(), toUpperCase()?
Even without them, just find a relationship between lower case and upper case ASCII values and do it that way.

[/ QUOTE ]

Most likely the second part is what is required. Just do a check for the value and if less than X, add Y, etc. Get a chart of the values and you should be good.

kurosh
11-01-2005, 05:35 PM
Already did it. Converted them to integers then added or subtracted and converted them back.

asofel
11-01-2005, 05:50 PM
[ QUOTE ]
Already did it. Converted them to integers then added or subtracted and converted them back.

[/ QUOTE ]

oh ok cool.

btw, i know it sucks, but unless this is a completely meaningless major for you, really try to get through the programs yourself. ask 1000 questions, but make sure you can do things as well, or its going to get really hard at the end and you'll be frustrated as [censored]...

11-01-2005, 07:21 PM
A side note, even though you finished already.

Character.isUpperCase(ch)/Character.isLowerCase(ch)
Character.toUpperCase(ch)/Character.toLowerCase(ch)

These would have helped. I recommend that if you keep programming, make friends with the Java API. It will make your life a lot easier.

Shilly
11-01-2005, 07:24 PM
Wow, this reminds me of taking Java last year, but I wasn't smart enough to try to find someone to pay to do it for me.

BadBoyBenny
11-01-2005, 07:25 PM
[ QUOTE ]
Someone who struggles with syntax is not going to have success as a programmer.

[/ QUOTE ]

Especially after 5 classes