4/20/2019
Posted by 
  1. Program Kriptografi Caesar Cipher Dengan Java

Hey I'm making a simple caesar cipher in Java using the formula [x-> (x+shift-1) mod 127 + 1] I want to have my encrypted text to have the ASCII characters except the control characters(i.e from 32-127). How can I avoid the control characters from 0-31 applying in the encrypted text. Thank you.

Max CanlasMax Canlas

7 Answers

How about something like this:

Yulius Caesar dikenal dengan Caesar Cipher dengan mengganti posisi huruf awal dari. “Lagi senang program. Kriptografi dengan teknik transposisi chipper. Dengan kriptografi. Caesar, yaitu dengan mengganti masing-masing huruf dengan 3 huruf selanjutnya (disebut juga Additive/Substitution Cipher).

Caesar

Admittedly this treats 127 as a non-control character, which it isn't.. you may wish to tweak it to keep the range as [32, 126].

Jon SkeetJon Skeet

Map your characters from [32.127] to [0.95], do a mod 95+1 and map the result back to [32.127].

Andreas_DAndreas_D

Usually cipher text is base64 encoded, base16 (hex) also works well. Base64 is used most often for cipher text because it takes up less space than hex, hex is most commonly used for message digests. In the java.util.prefs.Base64 library you will find byteArrayToBase64() and base64ToByteArray().

On a side note you should NEVER write your own encryption algorithm for security reasons, you should be using a block cipher or stream cipher. I hope this is for fun!

rookrook

there! Is there any way to consider the whole range of characters? For example, 'á', 'é', 'ö', 'ñ', and not consider ' ' (the [Space])? (For example, my String is 'Hello World', and the standard result is 'Khoor#Zruog'; I want to erase that '#', so the result would be 'KhoorZruog')

I'm sure my answer is in this piece of code:

.. But I've tried some things, and the didn't work :S So, I'll wait for your answers :D See you!

RodolfoRodolfo

Why not try

Wilcom embroidery. for(int i = 0; i < length; i++){char c = chars[i]if(Character.isLetter(c)){int x = c - 32;x = (x + shift) % 96;chars[i] = (char) (x+32);}}

ObscureObscure
studentstudent
Tanujit RoyTanujit Roy

Not the answer you're looking for? Browse other questions tagged javacryptographyascii or ask your own question.

up vote 0 down vote favorite I have a project due tomorrow and I still can't figure it out. After reading my online textbooks for information on caesar ciphers and encryption, I still have no idea what to do. I am new to programming so most code is out of my league atm, yet this project seems way too advanced for only three weeks into the semester. Here is the instructions: You are tasked with implementing a Caesar Cipher. Your cipher must take two command line arguments, the unencrypted message and k, the amount of the shift. Your code will convert the unencrypted message into an encrypted one by shifting each letter, one by one. It should then print to the screen the new encrypted message. Capital letters should remain capital during the shift and lowercase letters should remain lower case. In addition, make sure spaces are not changed at all. If you can account for other punctuation not being changed, that is considered 'above and beyond'. How would I go about starting this project and could you explain it to someone who has 3 weeks of coding experience. java encryption

this question edited Jan 29 '14 at 21:54 Kara 3,313 8 33 50 asked Jan 28 '14 at 22:18 Gxfire 12 2 closed as too broad by ProgramFOX, donfuxx, Kevin Panko, Jubobs, mustaccio Nov 18 '14 at 20:11 Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers

up vote 2 down vote Step 1 Create your alphabet. char[] alphabet = {'A', 'B', 'C', .. , 'X', 'Y', 'Z'};

Step 2 Shift your plaintext. Assume that args[0] is your original message, and args[1] is your shift, as passed in from the command line. char[] plaintext = args[0].toCharArray();

int shift = args[1];

for(int i = 0; i < plaintext.length; i++) {

for(int j = 0; j < alphabet.length; j++) {

if(alphabet[j] plaintext[i]) {

plaintext[i] = alphabet[(j + shift) % alphabet.length];

}

}

}

Step 3 Put your shifted char array back into a string and output the answer. String ciphertext = new String(plaintext);

System.out.println(ciphertext);



this answer answered Jan 28 '14 at 22:35 Rainbolt 2,478 8 28

up vote 1 down vote This is homework, so yoProgram Kriptografi Caesar Cipher Dengan Java

Recommend:encryption - Java: Caesar Cipher won't println

Caesar

ve been working on this for hours and am at a wall. Here is the code: import java.util.Scanner;public class caesartwo {public static void main(String[] args) {

Program Kriptografi Caesar Cipher Dengan Java

Scanner keyboard = new Scanner(System.in);

String originalText;

i

u're probably not going to get a lot of full answers. But here's some general guidance: 1 - Spaces are mentioned. So you need to take your input as a single string and then break it down (split) into an array of words. This will be the master array you scroll through, when this loop is done, your program is done. 2 - Now you need to take the elements of you array (which are the individual words) and process them by each letter. You need to loop through the characters of each word and apply the shift (k) 3 - Once thats complete, you need to 're-assemble' your phrase but adding a space after each word in your master array. Output that to the screen as your 'encrypted' message.

this answer answered Jan 28 '14 at 22:33 DMS 1,840 12 55 102 up vote 1 down vote You will need to look at: Scanner class to read arguments in from the command line java.lang.String class to turn a String of characters into separate character array elements incrementing and decrementing characters to add 3 to encrypt or subtract 3 to de-crypt. See this tutorial on incrementing characters: https://stackoverflow.com/questions/2899301/how-do-i-increment-a-variable-to-the-next-or-previous-letter-in-the-alphabet-in This is a tough project for a beginning class. Check out this small program I made to show how to increment a character from the lowercase letter a to the lowercase letter b.

public class alphabet {

public static void main(String[] args) {

char a = 'a';

System.out.println('a currently equals: ' + a);

System.out.println('++a now equals: ' + (++a));

}

}



this answer answered Jan 28 '14 at 22:36 user_loser 487 1 7 20

up vote 1 down vote Create an array that contains the characters you want to encrypt (order doesn't matter). Look up the % operator in java and use it compute an encrypted value for each item in the input string. Pseudocode Example find normal index in array (deal with case and special characters) compute an offset index using array.length % k look up a new 'encrypted' value using the offset index You may find the Character class useful.

this answer edited Nov 18 '14 at 18:42 Jubobs 22.9k 12 58 92 answered Jan 28 '14 at 22:34 cyber-monk 3,855 5 21 36 Not the answer you're looking for? Browse other questions tagged java encryption or ask your own question.

Recommend:encryption - java caesar cipher code

key ! here is my code public class CaesarCipher{ public static final String ALPHABET = 'abcdefghijklmnopqrstuvwxyz'; public static String encrypt(String plainText, int shiftKey) { plainText = plainText.toLowerCase();

Wings Xp 5 Emulator