#School assignment
1 messages · Page 1 of 1 (latest)
can you please directly share your question
dont ask to ask
and share everything here
so people can actually help
Also share where/why you got stuck.
the likelyhood that your professor is here is almost 0
it's not against the rules to get help, it's against the rules to use code that isnt yours
we wont give the solution
okk I get it
so basically should I send the codes that I already have and explain where i’m stuck?
Yup
yeah
And please use:
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
what if my program doesn’t have an error but just needs an extension to it. I don’t want someone to send me the code but just to explain how to go about it
okayy so basically it’s an encryption and decryption program that needs to meet certain demands, and there’s this one where you have to ask the user to input a 4 digita value that are going to be used in rotation to decrypt/encrypt the message
using the mod operator I think and it’s just confusing to set that up in a loop
sounds like a modified caesar cipher. Have you implemented the plain-jane caesar cipher yet? If not i suggest doing that (both encrypt + decrypt) and iterating from there
and please give more context
yess it is the caesar cipher, but the thing is my teacher said we have to come up with our own codes using the materials learned in class
I guess i’m really struggling with whether I should great 4 new variables for each number of the code and how am I supposed to implement the mod operator
so what do you mean by the 4 variables like
x1 x2 x3 x4 x5 x6 x7 x8
| | | | | | | |
v v v v v v v v
+A +B +C +D +A +B +C +D
```?
Detected code, here are some useful tools:
where the shift isnt constant but rotated by one of 4 possible values
like an integer variable for each number in the 4 digit key that the user inputs
I’m not even sure if i should do that
I just need to know whether it’s a good idea or not
are you encrypting the 4 digit input or is that being used as the encryption key
the encryption key
ok, so if the user enters 2573 what does that do
its supposed to shift each character in the message by that value in order
but if the message it’s longer than 4
it just like
so you're shifting each character by 2573 characters?
no, the first one gets shifted by 2, the second by 5, the third by 7 the fourth by 3 and if the message is longer it just goes back to 2 and repeats
My interpretation of what it should be is the
1st character -> +2 chars
2nd character -> +5 chars
3rd character -> +7 chars
4th character -> +3 chars
5th character -> +2 chars
yea
wdym thats exactly the thing u just said in a vertical format
but use an int[] for the offset values, not individual variables
what’s offest value
the 2 5 7 3
but the thing is
the key is like one single number with 4 digits
that I don’t know what they’re going to be so i can’t just add each number to a character
right, thats why you store the input in variables or an a array
prefer array
or even a dedicated class
but with array you can easily access them correctly using index and some modulo operation
all i’m allowed to use is strings, int, loops, mod operator, if statements
so the coding gets very tricky
💀 💀 💀
if (x % 4 == 3) {
offset = offset4
}```
☠️
hell nah 💀
which i highly doubt
the teacher didn’t even teach arrays
bro did not cook
you could read each char of the string though 🤔
yess that’s what i did so far
so i guess if you're not using arrays you'd have to use
int offsetType = x % y;```
Where x and y are up to you partially
thats not really related to the question though
then you can if statement (cause you dont have switch apparently) your way through assigning the correct offset value based on the type (type 1, 2, 3, or 4)
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
ohh in on the phone i can’tt
On android at least
im not sure why you are displaying digits only
basically
below that i also displayed letters
but i had to wrapped the letters and digits so that yk on the ASCII table
when it gets shifted it doesn’t become a strange character
also I recommend java if ('0' <= c && c <= '9')
if you're not able to use Character.isDigit
okayy thank youu
it'll auto cast char to ascii and vise versa
but you're saying that you want to map each character to a normal letter/number?
yess i already did that
and my program works fine
its just right now
its set up so that the user that to input a number between 1 and 9 so that
all the characters get shifted by the same number
now i have to make the input a 4 digit number
i guess do some validations and then .charAt(0-3)
what are validations
you probably dont have to worry about displaying any errors/preventing errors but like validating that the input was a 4 digit number
ok so you stored each number in the 4 variables you mentioned earlier?