Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue244 fix #294

Open
wants to merge 1 commit into
base: 2024/x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions substitution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,78 @@ def compiles():
@check50.check(compiles)
def encrypt1():
"""encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key"""
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("A").stdout("ciphertext:\s*Z\n", "ciphertext: Z\n").exit(0)
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("A").stdout(
"ciphertext:\s*Z\n", "ciphertext: Z\n"
).exit(0)


@check50.check(compiles)
def encrypt2():
"""encrypts "a" as "z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key"""
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("a").stdout("ciphertext:\s*z\n", "ciphertext: z\n").exit(0)
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("a").stdout(
"ciphertext:\s*z\n", "ciphertext: z\n"
).exit(0)


@check50.check(compiles)
def encrypt3():
"""encrypts "ABC" as "NJQ" using NJQSUYBRXMOPFTHZVAWCGILKED as key"""
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("ABC").stdout("ciphertext:\s*NJQ\n", "ciphertext: NJQ\n").exit(0)
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("ABC").stdout(
"ciphertext:\s*NJQ\n", "ciphertext: NJQ\n"
).exit(0)


@check50.check(compiles)
def encrypt4():
"""encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key"""
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("XyZ").stdout("ciphertext:\s*KeD\n", "ciphertext: KeD\n").exit(0)
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("XyZ").stdout(
"ciphertext:\s*KeD\n", "ciphertext: KeD\n"
).exit(0)


@check50.check(compiles)
def encrypt5():
"""encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key"""
check50.run("./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
check50.run("./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD").stdin(
"This is CS50"
).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)


@check50.check(compiles)
def encrypt6():
"""encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key"""
check50.run("./substitution yukfrnlbavmwzteogxhcipjsqd").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
check50.run("./substitution yukfrnlbavmwzteogxhcipjsqd").stdin(
"This is CS50"
).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)


@check50.check(compiles)
def encrypt7():
"""encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key"""
check50.run("./substitution YUKFRNLBAVMWZteogxhcipjsqd").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
check50.run("./substitution YUKFRNLBAVMWZteogxhcipjsqd").stdin(
"This is CS50"
).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)


@check50.check(compiles)
def encrypt8():
"""encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key"""
check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin("The quick brown fox jumps over the lazy dog").stdout("ciphertext:\s*Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n", "ciphertext: Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n").exit(0)
check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin(
"The quick brown fox jumps over the lazy dog"
).stdout(
"ciphertext:\s*Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n",
"ciphertext: Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n",
).exit(0)


@check50.check(compiles)
def encrypt9():
"""does not encrypt non-alphabetical characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key"""
check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin("Shh... Don't tell!").stdout("ciphertext:\s*Yqq... Sjf'r rxcc!\n", "ciphertext: Yqq... Sjf'r rxcc!\n").exit(0)
check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin(
"Shh... Don't tell!"
).stdout(
"ciphertext:\s*Yqq... Sjf'r rxcc!\n", "ciphertext: Yqq... Sjf'r rxcc!\n"
).exit(0)


@check50.check(compiles)
Expand Down Expand Up @@ -108,3 +131,9 @@ def handles_duplicate_chars_lower():
def handles_multiple_duplicate_chars():
"""handles multiple duplicate characters in key"""
check50.run("./substitution MMCcEFGHIJKLMNOPqRqTUVWXeZ").exit(1)


@check50.check(compiles)
def handles_single_duplicate_character():
"""handles a single mixed-case duplicate character in key"""
check50.run("./substitution ABCDEFGHIJKLMNOPpQRSTUVWXY").exit(1)