caesar-cipher

Caesar Cipher Shift (using alphabet array)

元气小坏坏 提交于 2019-11-29 15:29:49
I am currently writing a Caesar Cipher program in C# for my assignment and I am having a problem. I am approaching this task using an array where I store the whole alphabet and I declare a shift variable which is defined by character index in the array - the iteration of a for loop. The shift calculation is done in a foreach loop, that fetches a character from a string that is read from a text file. Foreach loop is contained within a for loop that iterates to output every possible shift. However, the problem is that when I try to access the character in an array by a value of my shift variable

java caesar cipher code

一笑奈何 提交于 2019-11-28 14:51:29
i did caesar cipher code by java it runs but doesnt encrypt anything after user enter the 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(); String cipherText = ""; for (int i = 0; i < plainText.length(); i++) { int charPosition = ALPHABET.indexOf(plainText.charAt(i)); int keyVal = (shiftKey + charPosition) % 26; char replaceVal = ALPHABET.charAt(keyVal); cipherText += replaceVal; } return cipherText; } public static String

How do you handle the shift on a Caesar cipher in Javascript?

可紊 提交于 2019-11-28 12:08:39
问题 I'm trying to create a caesar cipher in Javascript and having trouble figuring out how to do the shift. It may be that my approach is complicating it, but I'm trying to understand how to set a max value for adding numbers, but have the addition continue starting from the minimum number. Here is the code I have: $(document).ready(function(){ var alpha = []; var encoded = []; alpha = { '1': 'a', '2': 'b', '3': 'c', '4': 'd', '5': 'e', '6': 'f', '7': 'g', '8': 'h', '9': 'i', '10': 'j', '11': 'k'

Caesar Cipher Shift (using alphabet array)

佐手、 提交于 2019-11-28 09:10:37
问题 I am currently writing a Caesar Cipher program in C# for my assignment and I am having a problem. I am approaching this task using an array where I store the whole alphabet and I declare a shift variable which is defined by character index in the array - the iteration of a for loop. The shift calculation is done in a foreach loop, that fetches a character from a string that is read from a text file. Foreach loop is contained within a for loop that iterates to output every possible shift.

Caesar Cipher issue

你。 提交于 2019-11-28 01:46:49
I am trying to implement a Caesar cipher. I have tried to return message in the function, but I get an error message (outside function). Can anyone help, please? Thanks in advance cat cate catec catecv message = input("type message ") shift = int(input("Enter number to code ")) message = message.lower() #convets to lower case print (message) for a in message: if a in "abcdefghijklmnopqrstuvwxyz": number = ord(a) number += shift if number > ord("z"): number -= 26 elif number < ord("a"): number += 26 message = message + (chr ( number)) print (message) jfs Here's Python 3 Caesar cipher

Caesar Cipher issue

送分小仙女□ 提交于 2019-11-26 21:59:36
问题 I am trying to implement a Caesar cipher. I have tried to return message in the function, but I get an error message (outside function). Can anyone help, please? Thanks in advance cat cate catec catecv message = input("type message ") shift = int(input("Enter number to code ")) message = message.lower() #convets to lower case print (message) for a in message: if a in "abcdefghijklmnopqrstuvwxyz": number = ord(a) number += shift if number > ord("z"): number -= 26 elif number < ord("a"): number

Caesar Cipher Function in Python

馋奶兔 提交于 2019-11-26 03:25:29
问题 I\'m trying to create a simple Caesar Cipher function in Python that shifts letters based on input from the user and creates a final, new string at the end. The only problem is that the final cipher text shows only the last shifted character, not an entire string with all the shifted characters. Here\'s my code: plainText = raw_input(\"What is your plaintext? \") shift = int(raw_input(\"What is your shift? \")) def caesar(plainText, shift): for ch in plainText: if ch.isalpha(): stayInAlphabet