Forum Comments

7/15 Homework: Logic gates and truth tables
In CS Fundamentals for ACSL
winstygu
Jul 18, 2020
~A + B + ~C * ~D 3 false outputs
0
0
6/17 homework: Computer Number Systems, part 2
In CS Fundamentals for ACSL
Methods Homework 4/25/2020
In Java Question Bank
winstygu
May 02, 2020
import java.util.*; import java.io.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please enter your text to encrypt"); String in_text = sc.nextLine(); System.out.println("Please enter the number of shift(1-25)"); int shift = sc.nextInt(); System.out.println("Your encrypted message is " + encrypt(in_text,shift)); Scanner sc2 = new Scanner(System.in); System.out.println("Please enter your text to decrypt"); String in_text2 = sc2.nextLine(); System.out.println("Please enter the number of shift(1-25)"); int shift2 = sc2.nextInt(); System.out.println("Your decrypted message is " + decrypt(in_text2,shift2)); } public static String encrypt(String in_text,int shift) { String ciphertext =""; char alphabet; for (int i=0; i<in_text.length(); i++){ alphabet = in_text.charAt(i); if (alphabet>= 'a'&& alphabet <='z'){ alphabet = (char) (alphabet + shift); if (alphabet>'z'){ alphabet= (char)(alphabet-26); } ciphertext = ciphertext+alphabet; } else if (alphabet>= 'A'&& alphabet <='Z'){ alphabet = (char) (alphabet + shift); if (alphabet>'Z'){ alphabet= (char)(alphabet-26); } ciphertext = ciphertext+alphabet; System.out.println("ciphertext="+ciphertext); } } return ciphertext; } public static String decrypt(String in_text,int shift) { String plaintext = ""; char alphabet; for (int i=0; i<in_text.length(); i++){ alphabet = in_text.charAt(i); if (alphabet>= 'a'&& alphabet <='z'){ alphabet = (char) (alphabet - shift); if (alphabet<'a'){ alphabet= (char)(alphabet+26); } plaintext = plaintext+alphabet; } else if (alphabet>= 'A'&& alphabet <='Z'){ alphabet = (char) (alphabet - shift); if (alphabet<'A'){ alphabet= (char)(alphabet+26); } plaintext = plaintext+alphabet; //System.out.println("plaintext="+plaintext); } } return plaintext; } }
0
w
winstygu
More actions