+ 2
Checkout my Encryption program.
9 odpowiedzi
+ 7
Here's a spy cipher using ordinary words
https://code.sololearn.com/cyT21dfsDBV8/?ref=app
+ 5
https://code.sololearn.com/cFN7239wCiPC/?ref=app
this is my python version of this. it was a exercise for a online MIT programming class which I modified for sololearn (hence the use of classes)
+ 4
This has similar results, but adds each numeric cipher to a space seperated string and outputs it.
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
System.out.print("Enter your message: ");
Scanner sc = new Scanner(System.in);
char[] letters = sc.nextLine()
.toLowerCase()
.toCharArray();
String enc = "";
for(char letter: letters) {
if(char == ' '){
enc += "100 "
} else {
enc += (int)letter-96 + " ";
}
}
System.out.println(enc);
}
}
So a or A = 1 <-> z or Z = 26 while a space = 100
+ 3
A few tips:
1: This isn't true encryption, but really a simple numeric cipher. (ok for learning/practicing your code, but don't use in the real world) (this is not meant to knock, diss, or put down your code)
2: You're setting each character to the Letter Object replacing what the Letter Object is each time so that when the for loop is finished you'll only have the numeric cipher value of the last charater.
3: You can greatly reduce your code and eliminate the use of the if statements entirely by setting the input string to lower case and then creating a char array from it. You can then use integer math with the ascii value of lower case 'a' minus 1 to set the cipher values of each char in a for loop. You can then add these chars to a new string so that you aren't losing each previous char.
I'll post some sample code for you in a few. Good luck! Keep coding!
+ 2
Trust me i knew all the limitations of my code before you mentioned it. In regards to the encryption or rather cipher, it was just a simple program. I am still learning. Thanks for the feedback though and i will definitely keep coding.
+ 2
I kinda figured that was the case. 😉
+ 2
you should better use switch or else if statement, so that the code becomes faster.
the way you coded your if statements they all get checked, where if you would use else if, only the matching one gets executed without checking the rest.
+ 2
plus you are using a form of Ceasar's Encryption.
it is know to be vulnerable, because someone can understand what letter is each number due to the sequence of a letter in a word