-3

When i try to run this code:

 from base64 import b64encode, b64decode

 k = '1de76ec9fc46fab7'

 def modchar(c, i):
     return chr((((((ord(c) - 32) + i) % 94) + 94) % 94) + 32)

 def decode(s):
     global k
     r = ''
     n = 0
     for i in range(len(s)):
         r += modchar(s[i], -(int(i * 1.3) + i + len(s) - ord(k[n % len(k)]) + 109))
         n += 1
     return b64decode(r)

 def encode(s):
     global k
     r = ''
     n = 0
     s = b64encode(s)
     for i in range(len(s)):
         r += modchar(s[i], (int(i * 1.3) + i + len(s) - ord(k[n % len(k)]) + 109))
         n += 1
     return r


 print decode("/cUY")
 print encode('110')

On this site: https://www.programiz.com/python-programming/online-compiler/

Is giving this error:

 File "<string>", line 28
     print decode("/cUY")
           ^
 SyntaxError: invalid syntax
 > 

What am i doing wrong?

Thank you.

  • 3
    The online compiler is using Python 3, and `print` is a *function*, not a statement as it was in Python 2. – chepner Aug 23 '21 at 13:43
  • 1
    Your syntax _is_ invalid for Python 3. If you are only just learning the basics, you should probably ignore Python 2, and spend your time on the currently recommended and supported version of the language, which is Python 3. – tripleee Aug 23 '21 at 13:43
  • change `print x` --> `print(x)` – balderman Aug 23 '21 at 13:44

1 Answers1

0

You are trying to run python2 code with a python3 interpreter. That is why you get a SyntaxError. Try using python2 or use print(decode("/cuY")) with python3.

melvio
  • 762
  • 6
  • 24