Two Plus Two Older Archives

Two Plus Two Older Archives (http://archives2.twoplustwo.com/index.php)
-   Other Other Topics (http://archives2.twoplustwo.com/forumdisplay.php?f=32)
-   -   $10 to finish this java program for me (http://archives2.twoplustwo.com/showthread.php?t=369604)

kurosh 11-01-2005 01:20 PM

Re: $10 to finish this java program for me
 
[ 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

Re: $10 to finish this java program for me
 
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

Re: $10 to finish this java program for me
 
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

Re: $10 to finish this java program for me
 
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

Re: $10 to finish this java program for me
 
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

Re: $10 to finish this java program for me
 
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

Re: $10 to finish this java program for me
 
[ 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

Re: $10 to finish this java program for me
 
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

Re: $10 to finish this java program for me
 
[ 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

Re: $10 to finish this java program for me
 
[ 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.


All times are GMT -4. The time now is 01:29 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.