def test_rot13():
    assert (rot13("SERR PBQR PNZC") == "FREE CODE CAMP")
    assert (rot13("SERR CVMMN!") == "FREE PIZZA!")
    assert (rot13("SERR YBIR?") == "FREE LOVE?")
    assert (rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.") ==
            "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.")
    print("YOUR CODE IS CORRECT!")
Exemple #2
0
def test_rot13():
    upAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    lowAlpha = "abcdefghijklmnopqrstuvwxyz"
    upAlphaRot = upAlpha[13:] + upAlpha[:13]
    lowAlphaRot = lowAlpha[13:] + lowAlpha[:13]
    assert rot13(upAlpha) == upAlphaRot
    assert rot13(lowAlpha) == lowAlphaRot
    assert rot13("1234567890 !@#$%^&*()") == "1234567890 !@#$%^&*()"
    def test_symmetric_encryption(self):
        "Applying rot13 two times to a string returns the original string"
        self.assertEqual(rot13(rot13(lorem)), lorem)

        for i in range(50):
            random_text = ""
            for l in range(randrange(1,101)):
                random_text += choice(ascii_letters)
            random_text = "".join(random_text)

            self.assertEqual(rot13(rot13(random_text)), random_text)
Exemple #4
0
    def test_twice(self):
        "zweimal..."
        texts = [
            "Hello Python World", "To Be or Not To Be", "2b|!2b",
            """How do you keep a blonde busy for two days?
Tvir ure n cvrpr bs cncre gung unf "cyrnfr ghea bire"
jevggra ba obgu fvqrf.""",
            """What is it called when a blonde dies her hair brown?
Negvsvpvny vagryyvtrapr. """,
            """Wie bringt man die Augen einer Blondine zum leuchten?
Gnfpuraynzcr vaf Bue. """, """How to drown a blonde?
Zbhag gur zveebe ng gur cbby'f obggbz."""
        ]
        for text in texts:
            self.assertEqual(text, rot13(rot13(text)))
Exemple #5
0
    def post(self):
        text = self.request.get('text')
        text_rot13 = ''
        if text:
            text_rot13 = rot13(text)

        self.render('rot13.html', text = text_rot13)
Exemple #6
0
 def test_rot13(self):
     ptr = [
         ('EBG13 rknzcyr.', 'ROT13 example.'),
         ('ROT13 example.', 'EBG13 rknzcyr.'),
     ]
     for inp, exp in ptr:
         with self.subTest(inp=inp, exp=exp):
             self.assertEqual(rot13(message=inp), exp)
Exemple #7
0
def mensa(mensaj, rot13Val):
    if (rot13Val):
        mens = rot13(open(str(mensaj), "r").read())
    else:
        mens = open(str(mensaj), "r").read()
    # mens = open(str(mensaj), "rb").read().decode()
    mensa = tobits(mens, '2')
    mens = ''.join([str(elem) for elem in mensa])
    sis = os.path.getsize(mensaj)
    return mens, sis
Exemple #8
0
def main(request):
    t = loader.get_template('page.html')
    if request.method == "GET":
        c = Context({})
        return HttpResponse(t.render(c))
    elif request.method == "POST":
        user_input = request.POST['text']
        result = rot13(user_input)
        c = Context({'content': result})
        return HttpResponse(t.render(c))
Exemple #9
0
def test_rot13():
    """ Basic test cases for rot13 """
    assert rot13.rot13('abcdefghijklm') == 'nopqrstuvwxyz'
    assert rot13.rot13('nopqrstuvwxyz') == 'abcdefghijklm'
    assert rot13.rot13('abcdefghijklm'.upper()) == 'nopqrstuvwxyz'.upper()
    assert rot13.rot13('nopqrstuvwxyz'.upper()) == 'abcdefghijklm'.upper()

    assert rot13.rot13(rot13.rot13('This is a test')) == 'This is a test'
def test_2():
    test2 = """
        Rot13 or Rot-13 (short for rotate 13) is a simple letter substitution \
        encryption scheme. It works by replacing the current english letters \
        in a message with those that are 13 positions ahead in the alphabet. \
        For example, the letter a is replaced by n, b by o, c by p, etc. \
        Numbers and punctuation are not encoded.
        """
    test2_output = """
        Ebg13 be Ebg-13 (fubeg sbe ebgngr 13) vf n fvzcyr yrggre fhofgvghgvba \
        rapelcgvba fpurzr. Vg jbexf ol ercynpvat gur pheerag ratyvfu yrggref \
        va n zrffntr jvgu gubfr gung ner 13 cbfvgvbaf nurnq va gur nycunorg. \
        Sbe rknzcyr, gur yrggre n vf ercynprq ol a, o ol b, p ol c, rgp. \
        Ahzoref naq chapghngvba ner abg rapbqrq.
        """
    assert rot13(test2) == test2_output
Exemple #11
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s',
                        filename=os.path.join(os.path.dirname(__file__), \
                        'info.log'), level=logging.INFO)
    hostname = socket.gethostbyname(socket.gethostname())
    port = 9998
    logging.info(f'Listening on {hostname} port {port}')
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as ss:
        ss.bind((hostname, port))
        ss.listen(10)
        conn, addr = ss.accept()
        with conn:
            logging.info(f'Connected. IP: {addr}')
            while True:
                data = conn.recv(1024)
                if not data:
                    break
                logging.info(f'Received: {data.decode()}')
                conn.send(rot13(data.decode()).encode())
def act(controller, bundle, options):
    '''
    Required action method
    '''
    
    context = cp.get_context(controller)
    selection, range = cp.selection_and_range(context)
    
    # do nothing unless they selected something
    if range.length == 0:
        return
    
    try:
        text = selection.encode('rot13')
    except LookupError:
        # for python 3... hopefully one of the two will do the trick.
        import rot13
        text = rot13.rot13(selection)
    
    cp.insert_text(context, text, range)
Exemple #13
0
def test_capitals():
    """Verify rot13 works as expected on single capital letters"""
    assert r.rot13('A') == 'N'
    assert r.rot13('Z') == 'M'
Exemple #14
0
def test_rot13_1():
    assert rot13("This is a test!") == "Guvf vf n grfg!"
Exemple #15
0
def test_rot():
    assert 'Hello, World!' == rot13('Uryyb, Jbeyq!')
Exemple #16
0
def test():
    assert rot13("hello") == "uryyb"
def test_rot13_2():
    assert rot13("The quick brown fox jumps over the lazy dog.") == \
    "Gur dhvpx oebja sbk whzcf bire gur ynml qbt."
Exemple #18
0
import socket
from rot13 import rot13

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as ss:
    ss.bind((socket.gethostname(), 9999))
    ss.listen(1)
    conn, addr = ss.accept()
    with conn:
        print('Connected. IP:', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.send(rot13(data.decode()).encode())
 def test_empty_string(self):
     "Rot13 of an empty string is an empty string"
     self.assertEqual(rot13(""), "")
Exemple #20
0
 def test_basics(self):
     "basics"
     self.assertEqual("abcdefghijklm", rot13("nopqrstuvwxyz"))
     self.assertEqual("ABCDEFGHIJKLM", rot13("NOPQRSTUVWXYZ"))
     self.assertEqual("nopqrstuvwxyz", rot13("abcdefghijklm"))
     self.assertEqual("NOPQRSTUVWXYZ", rot13("ABCDEFGHIJKLM"))
def test_Rot13(str):
  """
  Функция проверяет функцию шифрования Rot13
  """
  assert(r.rot13(r.rot13(str)) == str) 
  return r.rot13(r.rot13(str)) == str
Exemple #22
0
def test_validation():
    assert(rot13(None) is None)
    assert(rot13(1) is None)
    assert(rot13("") == "")
Exemple #23
0
def test_lower_case():
    assert(rot13("abcd") == "nopq")
    assert(rot13("nopq") == "abcd")
Exemple #24
0
def test_punctuation():
    assert(rot13("We're knights of the Round Table!") ==
           "Jr'er xavtugf bs gur Ebhaq Gnoyr!")
    assert(rot13("Jr'er xavtugf bs gur Ebhaq Gnoyr!") ==
           "We're knights of the Round Table!")
Exemple #25
0
def test_mixed_case():
    assert(rot13("Python") == "Clguba")
Exemple #26
0
def test_upper_case():
    assert(rot13("EFGH") == "RSTU")
    assert(rot13("RSTU") == "EFGH")
Exemple #27
0
def test_rot13(s):
    """Test jednoduché šifry typu ROT13."""
    assert rot13(rot13(s)) == s
Exemple #28
0
def test_rot13_3():
    assert rot13("Gur dhvpx oebja sbk whzcf bire gur ynml qbt.") == \
    "The quick brown fox jumps over the lazy dog."
Exemple #29
0
def test_rot13(input, output):
    from rot13 import rot13
    assert rot13(input) == output
Exemple #30
0
def test_inversion_simple():
    """Verify that using the function twice returns the same string"""
    test_string = "Hello, world. Here is a test string. 1, 2; 3"
    assert test_string == r.rot13(r.rot13(test_string))
def test_1():
    test = "The ROT13 encryption scheme is a simple substitution cyper.?1!"
    test_output = "Gur EBG13 rapelcgvba fpurzr vf n fvzcyr fhofgvghgvba plcre.?1!"
    assert rot13(test) == test_output
# encryption_testing.py

import rot13

print("testing the rot13.py program and the use of modules:")
print(rot13.rot13('Ask not what your country can do for you.'))
 def test_programming_praxis(self):
     crypted = "Cebtenzzvat Cenkvf vf sha!"
     uncrypted = "Programming Praxis is fun!"
     self.assertEqual(rot13(crypted), uncrypted)
Exemple #34
0
def test_nonletters():
    """Verify that it returns non-letter characters unchanged"""
    assert r.rot13(" ?^%81") == " ?^%81"
def test_rot13_1():
    assert rot13("This is a test!") == "Guvf vf n grfg!"
 def post(self):
     raw_text = self.request.get('text')
     self.write_form(rot13.rot13(raw_text))
 def static(d):
     self.assertEqual(rot13(d),sol(d))
     self.assertEqual(rot13(rot13(d)),d)
Exemple #38
0
def test_lowercase():
    """Verify rot13 works as expected on single capital letters"""
    assert r.rot13('a') == 'n'
    assert r.rot13('q') == 'd'
Exemple #39
0
 def test_nonascii(self):
     "nonascii"
     self.assertEqual("0123456789", rot13("0123456789"))
     self.assertEqual(" ,;.-?=)(/&%$§!", rot13(" ,;.-?=)(/&%$§!"))
Exemple #40
0
from rot13 import rot13
from dedupe import dedupe
from leetspeak import leetspeak
from multiply import multiply
from smallest_number import smallest_number
from longvowel import longvowel

text = "lbh zhfg hayrnea jung lbh unir yrnearq"
print("Converting this ROT13 encoded text: %s" % text)
print(rot13(text))
print()

list_to_dedupe = [1, 3, 4, 4, 23, 1, 0, 100]
print("Deduping this list: %s" % list_to_dedupe)
print(dedupe(list_to_dedupe))
print()

text_to_convert = "elite speak"
print("Converting this to leetspeak: %s" % text_to_convert)
print(leetspeak(text_to_convert))
print()

numbers_to_multiply = [1, 45, -67, 62, 0, -1]
multiplication_factor = 5
print("Multiplying these numbers by %d: %s" %
      (multiplication_factor, numbers_to_multiply))
print(multiply(numbers_to_multiply, multiplication_factor))
print()

list_of_numbers = [1, 45, 62, 0, -1]
print("Finding smallest number in this list: %s" % list_of_numbers)
Exemple #41
0
 def test_example(self):
     "beispiel"
     self.assertEqual("Clguba vfg gbyy!", rot13("Python ist toll!"))
Exemple #42
0
from rot13 import rot13

print(rot13('GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.'))

from test_rot13 import test_rot13

test_rot13()