caesar-cipher

How do I make a javascript function a html attribute?

点点圈 提交于 2020-04-18 05:47:54
问题 I have a javascript variable with parameters, but I don't know how to pass it into my html code. The javascript code is taken from https://gist.github.com/EvanHahn/2587465: var caesarShift = function(str, amount) { // Wrap the amount if (amount < 0) return caesarShift(str, amount + 26); // Make an output variable var output = ''; // Go through each character for (var i = 0; i < str.length; i ++) { // Get the character we'll be appending var c = str[i]; // If it's a letter... if (c.match(/[a-z

How to preserve case of characters when using Caesar Cipher

谁说胖子不能爱 提交于 2020-01-25 02:47:10
问题 I have a Caesar Cipher script in Ruby that is working but it returns the string as all upper-case letters instead of preserving the cases of the original string. I could use capitalize to make it look good enough but I would like a more concrete way of preserving the cases. Here is the script: BASE_ORD = 'A'.ord def caesar_cipher(phrase, key) cipher = phrase.gsub(/[a-z]/i) do |c| orig_pos = c.upcase.ord - BASE_ORD new_pos = (orig_pos + key) % 26 (new_pos + BASE_ORD).chr end puts cipher end

php Substitution Encoding Algorithm using cesar cipher

。_饼干妹妹 提交于 2019-12-24 10:34:22
问题 hello i am stack with this exercise as part of a test, how can i solve it or hint to solve it /** * Class SubstitutionEncodingAlgorithm */ class SubstitutionEncodingAlgorithm implements EncodingAlgorithm { /** * @var array */ private $substitutions; /** * SubstitutionEncodingAlgorithm constructor. * @param $substitutions */ public function __construct(array $substitutions) { $this->substitutions = array(); } /** * Encodes text by substituting character with another one provided in the pair. *

Encryption and Decryption within the alphabet - Python GCSE

六眼飞鱼酱① 提交于 2019-12-20 07:56:09
问题 I am currently trying to write a program, for school, in order to encrypt and decrypt a inputted message. I need the encrypted or decrypted message to only be in the alphabet no other symbols or keys, for example, with an inputted offset of 5 using the message van to encrypt, i want it to output 'afs'. Can anyone help please? This is my code currently. def find_offset(): offset = int(input("Enter an offset: ")) if offset > 25 or offset < 0: print("Invalid offset, please enter another offset:

Need help ensuring text shifted 'x' amount of spaces is transformed into letters, not random symbols

戏子无情 提交于 2019-12-20 07:48:21
问题 I'm working on a page on cryptography, and have decided to include a Caesar Cipher, a method in which you shift a letter 'X' amount of spaces left or right. Example: Encrypting the letter 'A' with a shift parameter of 2. A => C. The code below is working somewhat decently. It's able to encrypt/decrypt the text I enter, as long as it's between certain ASCII values. The values 65-90 in ASCII is uppercase letters, and 97-122 is lowercase letters. My problem is if my shift parameter is so large,

java caesar cipher code

人盡茶涼 提交于 2019-12-17 21:37:45
问题 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

Caesar cipher in C working for lower not upper

China☆狼群 提交于 2019-12-13 22:12:30
问题 Cipher works for islower portion but not isupper portion. For instance if I give a key of 3 and enter I like pie!! to be encrypted, I get O olnh slh!! I also tried HELLO and got NKRRU . The isupper portion is also returning punctuation instead of just letters. I also have not figured out why the original message is being altered to match the cipher message. #include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main (int argc, string argv[]) { /*

How to make shift('w','f') return 'b'?

守給你的承諾、 提交于 2019-12-13 07:42:26
问题 Using this program to take out spaces, punctuation, and make letters lower case... def pre_process(s): #Enter: "Jim's secret password." s= s.replace("'","") s= s.replace('.','') s= s.lower() s= s.replace(" ","") return s How can I encrypt a message so that the letters each shift by an amount equal to the corresponding letter in the alphabet? For example m shifted 5 times becomes r , but w shifted 5 times becomes b . This is my current code: def shift(ch,k): return chr(ord('a')+(ord(ch)-ord('a

Wanted to do caesar's cipher but couldn't change the last two characters

大兔子大兔子 提交于 2019-12-12 23:57:31
问题 I wrote a code for caesar's cipher and the code works except I can't cipher more than 8 letters and I also can't handle spaces. It shows ">>" this symbol instead of spaces. Also, I wanted to do binary search in the second function of my code but I don't know whether I have done that or not. #include <stdio.h> #include <string.h> #include <stdlib.h> char caesar (char x, char alphabets[]); int j; int main() { char* plain_text = malloc (10 * sizeof(char) + 1); int key, num; char* cipher_text =

C# Caesar Cipher can't decipher

倾然丶 夕夏残阳落幕 提交于 2019-12-11 13:53:27
问题 I am trying to make a C# Caesar Cipher for an assignment. I have been trying to do this for quite a while and am making no headway whatsoever. The problem I am having now is that rather than use my encrypted_text and deciphering it, it just cycles through that alphabet, ignoring the character that it started on.What is supposed to happen is it is meant to take the encrypted_text and cycle through the alphabet changing each letter by a certain number. This is what I have so far: using System;