# Tag Info

### What's the point of the modulo operation in the Caesar cipher formula?

Let's consider the encryption formula given in the problem set: cᵢ = (pᵢ + k) % 26 Here, as in the problem set,cᵢ represents the value of the encrypted or enciphered letter, pᵢ represents the value ...
Accepted

### Modulo not working in caesar

Modulo is working correctly, but you've overlooked something. The idea behind using modulo is this. When you represent letters as numbers between 0 and 25 inclusive, and add a number to shift the ...

### why do we use remainder 26 (%26)?

% 26 will always give you a number between 0 and 25. The Caesar algorithm works on the assumption that your letters A-Z (or a-z) are represented by the numbers 0-25, so if you have 'z' (25) and a key ...

### What's the point of the modulo operation in the Caesar cipher formula?

The purpose of the formula is to calculate the new (cyphered) value for a given character on a string, considering a swift value. The formula has 4 components: ci = ciphered character pi = current ...
Accepted

### Modulo not working in Greedy

If you tried typecasting to int, still the error would have existed because you are still storing the value in a float. So its basically like, original value = 12.27 round()'s output = 1227.00 ...

### Modulo not working in Greedy

Modulo Operator ( % ) requires both the operands to be of type int . In your code change is a floating point variable. Use an integer variable to store the rounded value.
Accepted

### modulo returning wrong value in Greedy

That's how the remainder operator just works. You may think of it that way: given a = 3 and b = 2, the expression a % b // results in 1 because a 3 can have a maximum of a single (i.e., one) 2 in ...

### How to wrap around the jth element in vigenere cipher efficiently?

I am among those people who suggest you to use 2 loop variables, actually its 1. Use a variable (say i) to iterate over each element of the input string and maintain another variable (say j) to hover ...
Accepted

### pset2 Vigenere Modulo

In order to use modulo to wrap around the dictionary you first need to offset both key and plaintext to convert them to values between 0 and 25, and then add them and use modulo. That part is just as ...
Accepted

### Typecasting with Modulo in Greedy

Modulo only works with integers. You are attempting to apply it to a float. If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)
1 vote
Accepted

### cash CS50 2020 pset1 modulo

Why are you using modulo for this? It produces an unreliable result in this usage. Further, the actual numbers don't make sense. The modulo function returns the remainder after an integer division. ...
1 vote

### Why is d = 185 to satisfy de = 1 mod m (where m = 924)? (Wk2, shorts: cryptography)

de = 1 (mod m) where e is equal to 5 and m is equal to 924 means (5 * d) % 924 = 1 Thomas later in the video used the extended Euclidean algorithm to find a value of d that would satisfy the ...
1 vote
Accepted

### PSET1 - Credit Checksum Problem

test.c:35:49: error: invalid operands to binary expression ('double' and 'double') printf("%lld\n", ((l / (pow(10.00, i))) % 10)); ~~~~~~~~~~~~~~~~~~~~~ ^ ~~ 1 error ...
1 vote
Accepted

### PSet1 cash, modulo problem

Welcome to the world of (binary) floating point. A value like 4.2 cannot be precisely represented in binary, it would be represented by an infinite sequence of binary digits. Obviously we don't have ...
1 vote
Accepted

### Pset1 Cash Understanding modulo operator and while loops

You have created an infinite loop. If the loop starts, it will never exit the loop. It tests the value contained in amount to decide to continue or exit, but since the value of amount is not changed ...
1 vote
Accepted

### Pset 2 Caesar: "invalid operands to binary expression ('string' (aka 'char *') and 'int')"

In that formula, use p[i], the ith character of p, not p itself.
1 vote
Accepted

### Another modulo question for CS50 Caesar

I would suggest that you convert both your uppercase and lowercase chars into an index value of 0-25. That is the premise of the caesar formula.
1 vote
Accepted

### Trying to make cash.c from pset 1 without mod

Please have another look at the second hint of this exercise (https://docs.cs50.net/2018/x/psets/1/cash/cash.html#hints). After you have followed that advise, you will be able to use the modulo ...
1 vote
Accepted

### Output of characters at specific place place using uint_list

If you want to print something different based on a condition, you need to use a conditional like an if. As written this program will only ever output (sign) and 5 dashes. Full stop. This does not ...
1 vote
Accepted

### PSET1 / Credit / Modulo problem / Error: invalid operands to binary expression ('double' and 'double')

the definition of the pow function says that it returns a double that is the reason of your error, since the operator modulo requires integers, it is possible that it works if we do a casting although ...
1 vote

### Refactoring Pset1 Greedy Modulo

You could simply use coins as the variable that holds the coin value and add to it with each equation. coins = 0; coins += amount/25; ... coins += amount/10 .... etc etc. Then, at the end, coins ...
1 vote
Accepted

### vigenere key wraparound issue

Take a close look at this line and think very carefully about what the modulo operation is being applied to: int cipherKey = (((key[i]) - 'A') % KeyLen); It coverts a key letter to a number between ...
1 vote
Accepted

### greedy with modulo

You're creating multiple shadow variables in the code. A shadow variable is a new var with the same name as one that has been created earlier, but the new var is created in a place where it will have ...
1 vote
Accepted

### strange output in vigenere. Even when done by hand to add ascii values

We have 26 characters in English alphabet, so use %26 and not %25. Also, note what you apply that %26 to, you seem to apply it to tolower(argv[counter]) - 97 only instead of to the whole sum.
1 vote
Accepted

### Pset2 Vigenere z key stops functionning after e

By the let me tell you that your program is not working at all It's showing error something like this b.c:16:10: runtime error: null pointer passed as argument 1, which is declared to never be ...
1 vote

### pset2 Vigenere Modulo

You were correct. You must use the modulus operator to ensure that the text output is between A and Z. However, you are wrapping the key, so that it is from A to Z. You must wrap the output. So ...
1 vote

### How to wrap around the jth element in vigenere cipher efficiently?

another way to do it j++; j = j % v; where j is the jth char of key and v is strlen of key. when placed at the end of your shift functions within your if statement, j will increment only when you've ...
1 vote

### how do I restrict cipher to alpha only - I am getting symbols that come after "z"

A few errors to point out: your code is difficult to read because it has not been indented properly. I believe your formula for shifting the characters is wrong. Lets say we take 'z' which is 122 on ...
1 vote

### How to calculate modulo?

Lets find pow(x,y)%n Wikipedia lists this property here. Now, since we know how to find the modulus of product of 2 big numbers, then we can use this identity in the following way to do it for ...
1 vote

### How to calculate modulo?

After watching the short on RSA, I guess you didn't mean the XOR bitwise operator by the symbol (^), but rather, you meant exponent. The powl() function (declared in math.h) can be useful for that ...

Only top scored, non community-wiki answers of a minimum length are eligible