Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-151

Affine Cipher Encrypt

Problem

Encrypt uppercase text with an affine cipher: E(x) = (a * x + b) mod 26, where x is the letter index A=0. Return the uppercase ciphertext.

Hint

With a = 1 the affine cipher reduces to a Caesar shift.

Test cases

case 1
in: ["ABC",1,1]
expected: "BCD"
case 2
in: ["HELLO",1,3]
expected: "KHOOR"
case 3
in: ["ABC",5,8]
expected: "INS"
case 4
in: ["XYZ",1,1]
expected: "YZA"
case 5
in: ["SECRET",7,3]
expected: "ZFRSFG"
Starter codePython
def affine_encrypt(text, a, b):
    # Your code here
    pass

5 test cases · run your code against them in the editor