Hi im just learning java and im about to write my own encryption/decryption class.
Need abit help, it doesnt replace the character which i dont understand, it just returns the text message i wrote.
first file
second file
Im still learning OOP so im pretty new at this
Would appreciate if someone would take a look at it
Need abit help, it doesnt replace the character which i dont understand, it just returns the text message i wrote.
first file
Code:
class functions{
private String text;
private String[] encrypt = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"};
private String[] decrypt = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
//Encrypt text string and return result
public void encryptText(String text){
for(int i=0; i < 26; i++){
this.text = text.replace(decrypt[i],encrypt [i]);
}
}
//Decrypt text string and return result
public void decryptText(String text){
for(int i=0; i < 26; i++){
this.text = text.replace(encrypt [i],decrypt[i]);
}
}
public String getResult(){
return text;
}
}
second file
Code:
import java.util.Scanner;
class krypt {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
functions myFunc = new functions();
System.out.println("Type in a text to encrypt");
String text = sc.nextLine();
myFunc.encryptText(text);
System.out.println(myFunc.getResult());
}
}
Im still learning OOP so im pretty new at this
Would appreciate if someone would take a look at it









