Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to speed up my
"for loop"
that contains 7 more "for loops" inside. The idea is that you can run the function like this
breaker("akzH6Fs0")
and it will break the password that you wrote in the quotes. Sadly I get an error as in title. I tried to surf but nothing helps.
I'm using python 3.8.2 version.
Here's the code:
import time
cpdef breaker(char *a):
strings = list("abcčćdđefghijklmnoprsštuvzžqwxy1234567890ABCČĆDĐEFGHIJKLMNOPRSŠTUVZŽQWXY")
cdef char string1
cdef char string2
cdef char string3
cdef char string4
cdef char string5
cdef char string6
cdef char string7
cdef char string8
for string1 in strings:
for string2 in strings:
for string3 in strings:
for string4 in strings:
for string5 in strings:
for string6 in strings:
for string7 in strings:
for string8 in strings:
if a == string1 + string2 + string3 + string4 + string5 + string6 + string7 + string8:
password = string1 + string2 + string3 + string4 + string5 + string6 + string7 + string8
time.sleep(1)
print("your password is", password)
time.sleep(10)
quit()
print(string1 + string2 + string3 + string4 + string5 + string6 + string7 + string8)
Traceback (most recent call last):
File "C:\Users\korisnik\Desktop\edps_tests\testing.py", line 3, in <module>
edps_test.breaker("password")
File "edps_test.pyx", line 3, in edps_test.breaker
cpdef breaker(char *a):
TypeError: expected bytes, str found
[Finished in 0.2s with exit code 1]
[shell_cmd: python -u "C:\Users\korisnik\Desktop\edps_tests\testing.py"]
[dir: C:\Users\korisnik\Desktop\edps_tests]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\compiler;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;D:\webdrivers;C:\Users\korisnik\AppData\Local\Programs\Python\Python38-32\Scripts\;C:\Users\korisnik\AppData\Local\Programs\Python\Python38-32\;C:\Users\korisnik\AppData\Local\Microsoft\WindowsApps;C:\Users\korisnik\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\PyCharm Community Edition 2020.1\bin;]
Solution will be great but I will really appreciate just an explanation of the error and my mistake. I am begginer in cython by the way. Thanks in advance!
As your traceback points out, char* can't handle being passed a str. This is because in Python 3.* str is actually a unicode string container.
The safe way to accept string arguments from the interpreter is by declaring them as the str type. For example:
cpdef breaker(str a):
# etc...
See https://cython.readthedocs.io/en/latest/src/tutorial/strings.html#accepting-strings-from-python-code for more info.
Important note: As far as I can tell this function doesn't actually seem to be achieving anything. It will (very slowly) print the input string so long as it contains only characters in your defined string list. What are you trying to accomplish?
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.