Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //imagine eto yugn main file
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Day18Password callPass = new Day18Password();
- String txtIn = "";
- String txtOut = "";
- boolean encrypt = true;
- System.out.print("Enter text >> ");
- txtIn = sc.nextLine();
- System.out.print("encrypt(true/false) >> ");
- encrypt = sc.nextBoolean();
- callPass.setTxtIn(txtIn);
- callPass.setEncrypt(encrypt);
- txtOut = callPass.getTxtOut();
- System.out.println("encrypted: " + txtOut);
- }
- }
- //--------------------------------
- //eto yung isa pang file
- //encapsulation sample
- public class Day18Password { //BURAHIN NYO YUNG public KUNG GUSTO NYO ITO GAWIN SA ISANG FILE LANG
- private String txtIn = "";
- private String txtOut = "";
- private boolean encrypt;
- public void setTxtIn(String txtIn) {
- this.txtIn = txtIn;
- }
- public void setEncrypt(boolean encrypt) {
- this.encrypt = encrypt;
- }
- public String getTxtOut() {
- txtOut = caesarCipher(txtIn, encrypt);
- return txtOut;
- }
- private String caesarCipher(String txtIn, boolean encrypt){
- String txtOut = "";
- int increment = 2;
- if (encrypt == false) {
- increment = -2;
- }
- char txtArray[] = txtIn.toCharArray();
- for (char c : txtArray) {
- c += increment;
- txtOut += c;
- }
- return txtOut;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment