6 kyu
Crack the PIN
358 of 3,051zLuki
Loading description...
Algorithms
Cryptography
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
In C, I just brute-forced it. The main difficulty for me was importing the MD5 function on Windows. I tried linking MinGW against OpenSSL, but the MD5 function had already been deprecated. Eventually, I realized there are built-in packages in Windows:
#include <windows.h> #include <wincrypt.h> #pragma comment(lib, "advapi32.lib")
However, this doesn’t seem to work on Codewars. Not really surprised but what are the alternatives to access the MD5 function on the site ?
You can implement MD5 from scratch :) or you can use tools provided by the platform. Documentation for C setup mentions that library
crypto
is linked with code of C kata, and you can use OpenSSL'slibcrypto
and its functions.Or you can call command line utilities available on linux (but I do not know if they are installed in the CW runner).
my view is that
#include <openssl/md5.h>
should be present in the initial code. Many users are not aware that Codewars runs on Linux and that some libraries are installed, so these katas are unfair for them.Guiding users about available libraries sounds like a good idea, and I think that such
#include
can be added to solution setup, either as actual code, or as a commented-out suggestion that it can be one of possible ways to use utilities provided by the platform?in my translations to the other hash cracking katas (SHA-1, SHA-256), I imported the proper header with an
#include
in the initial code. I did the same in my pending translations involving threading, SQLite, and sockets.If I understand correctly you can import native Node.js packages inside the codewars environment?
Where's the list of all those packages available on codewars?
Here: https://docs.codewars.com/languages/javascript#node-modules
Well, yeah, but I am not seeing the library everybody used for solving this kata
If you're looking for NodeJS built-in modules, then take a look at NodeJS v18 API docs
"Every Website and OS is storing their passwords as hashes"
This statement is false.
I think the author meant : 'should store as hashes'. and in this time, not MD5 anymore, but salted ones.
Does somebody have idea why my code doesn't work for "random tests"?
*edit: I just had to click "attempt" button several times and mny code finally worked!
Your code is very inefficient with the random RNG seed generator
This comment has been hidden.
A simple google search would have done it and it is not the responsibility of kata authors to provide a clear mindset pathway on how to solve it. (Users can also estimate their code's complexity based on the kyu lvl)
This's good cata. First you think about brute force, estimate it as the number of operations equal to 9^5, think about the method of brute force... After that, you realize that everything is much easier. Good luck!
This comment has been hidden.
.
Initial solution in C++ is broken
.
This comment has been hidden.
There are random tests, what do you mean?
Add
srand(time(0));
at the start of 'It' block. IDK the specifics, but it seems to always be using the same seed for RNG, if it's not specified, which leads to same strings being generated.Done! Thank you guys :)
Python 3.8 should be enabled.
I can't edit the tests anymore, there is a lock symbol. What should I do?
Get 300 more honor, ask B1ts to look into it if possible, or wait for a week.
I enabled it, but now with 3.6 it fails when attempting. If that's normal behaviour, go ahead and close the issue.
Thank you B1ts!
Great kata. The difficulty level is just right for a 6kyu Node.js kata.
This comment has been hidden.
Make you code faster, codewars is much slower than your local machine :)
Could you please advise if this is possible to do before timeout(12s) in PowerShell? Thank you
(in C) I get the right answer, store it in string "expected" which is passed from main. All works fine while I'm in the crack function (i.e. I print "expected" to screen and confirm it is correct). In main, the value in "expected" is different. I am starring at my code for an hour now, with no idea what the problem may be. Any suggestions?
I got it! Your string chr_try is to small. It is of size 5 but we need 5 chars + \0 as terminator.
Change
to
That was it! Thank you so much, it was driving me nuts.
Fantastic kata! This was one of the most fun ones so far as I haven't implemented MD5 before.
How does one overcome the timeout issues with this cracking challenge?
It's easy possible in go, my solution takes 4 seconds.
don't use print(), if you use
I'm not using any prints. The main difference might be that I'm using a random generator, instead of increments.
Yeah it can't work with random, that's really bad.
It's not really bad. It's way more efficient in an actual attack scenario and potentially less suspicious than attempting incremental values. And by random I meant generating the pin codes manually, not fully random gibberish.
The naive approach is to make your md5Hash function return a 32 character string, and compare it to the hash that was sent to the function. Strings are slow. Try to compare byte buffers or arrays.
Great Kata , it was pleasure to do it. Also thanks for giat variety of available languages
Thanks for completing it! :)
( JS )
Random tests should be in an
it
within adescribe
( all tests should, but the rest already are ). Changing the currentdescribe
toit
and moving it to within the existingdescribe
works.The test framework is peculiar that way.
Fixed!
So touching care about developer in the warning comment about output in STDOUT for PHP and JS versions. Great kata, thank you.
A minor typo in the description:
Why is this useful[]?
thank you
Thank you. This kata was very fun.
Another fun one, thanks
thank you!
The PHPUnit cases have the asserions' arguments inversed. See https://phpunit.readthedocs.io/en/9.2/assertions.html#assertequals. This means, for example, if I return 'asd' the failed asserion message goes like this:
Failed asserting that two strings are equal. Expected: 'asd' Actual : '00078'
Obviously, it's the other way. It confused me at first. It should be an easy fix. Nice kata, though!
I fixed it, thanks for feedback! :)
Very nice explanation of the usefulness of a Hash function!
This comment has been hidden.
There is a syntax error at the java project. There are '()' after classname.
Fixed
I've got a time out issue when I do an attempt in python but it works fine when I do the test, maybe my code is not optimised enough but I also think it might be that the kata is not leaving enough time for the code to solve the tests in python
your code is to slow, that's not an issue
Hi, I am using JavaScript and my code is passing tests. But I am getting timeout error when pressing Attempt. It fails after 10 passed tests.
Your code is working, but it's too slow. Try to implement md5 faster. You don't have to write it yourself you can import a library :) I'm sure you'll make it!
Thx for answer. I am new here and I dont know, how can install and import library?
This comment has been hidden.
You can import a popular js libary, dont make the mistake I made and import one manually. Great Kata!
I made that mistake too lol.
C++ has a MD5 library imported, don't be stupid like me and import one in manually lol. Thanks for the kata, loved it!
Tanks for your feedback! :)
What library is imported in C++ and how do I use the md5 hash function?
Do some research about
Shell version is suffering from timeout issues. It needs to be changed or removed.
Not an issue, your implementation is too slow, mine works fine :)
Maybe you were extrem unlucky with random test, if you tried only once, but I tried my solutions 10 times now and it always worked fine.
For languages that do not suffer from timeout issues, edge cases of PIN '00000' and '99999' hashes should be added.
Added those tests to C, C++, C#, CoffeeScript, Dart, Java, Javascript, PHP, Python, Ruby and VB.
I updated CFML and Prolog to have them as well.
Thanks :)
I was thinking about making a Julia translation but the equivalent of hashlib in python is not available on CW. Writing the code raw is fine but more of a 4kyu than a 6kyu so not much point. But if the Nettle package was made available, it would be similar difficulty to python and other languages.
Can I do that or does a mod has to do that? (Sorry if my question is stupid :) )
Probably a mod but I don't really know. I don't think it can happen whilst Julia is still a Beta language :(
No mod / power-user can make these changes AFAIK, only admin @kazk.
You should check for open issues on GitHub and maybe open one if it's not there.
I didn't think it was possible, but... prolog translation :D Random tests can be increased up to around 100 if you wanna be more strict, but task itself looks hard enough.
Thanks!! :))
CFML translation kumited. CFML is quite slow, so I only added 10 random tests, but you can push it to around 20, if you want.
Thank you very much. 10 Random tests are ok for me. Another question only if you have time: Do you know why my shell random test isn't working? (If you select bash and click on Show kata Test cases you see it marked out with #)
This comment has been hidden.
Yeah shell is really slow, thanks for that code I will try it :)
https://www.codewars.com/kata/password-hashes for a kata about generating md5 hashes. (Not claiming this one is a duplicate).
thanks for your feedback, I'll add the link to the description
i liked your kata, i hope it'll make its way out of beta, especially since you took the time to make many translations :)
thank you so much! :)
js version would be 6, but might help to mention how to include or require extra script libraries. without using a require I imagine it would be more like a 2 or 3 if you needed to create your own md5 hash generator. At least is JS, not sure about other languages.
Thanks for your feedback! Like I wrote in the description, you are allowed to use require so you don't have to write your own md5 generator (obviously it would be a good exercise). In my view, it would be even to easy for 6, if I explain how to use require to hash md5. Have a nice evening :)
PHP: You don't need
<?php
in solution setup, and argument name is missing$
.It is fixed now, thanks for your comment :)
Still there are no False for a correct answer in the random tests.
FArekkusu told me to remove that, so I did it. There is no more input validation :)
True, didn't read that. It was useless validation
Can someone help me with the powershell version? Why is it so slow?
Maybe you don't have to make so many translations
Ok, thanks for the answer, I'll try to change that soon.
EDIT: I changed it now and it works! :))
Java version is broken.
Why in the world are you writing a greet function? What's
class person
?Haha, this is just the example case from code wars :) I'm working on a Java version and will publish it soon
BRUH, its already published
Yeah, i wanted to publish only powershell and i clicked on the X next to Java but I guess it didn't work :D
People should work on the java version for free honor. lol
I removed the java version, so that people can't get free honor for that. But I will release a working Java version soon :)
note: try to avoid removing languages versions: that's a buggy feature and can lead to troubles from time to time. :/
Ok, didn't know that. What can happen, if I do it?
The details are a little confusing for someone new to hash functions. Could you explain it more or add a link to somewhere that does?
I did that right now, thanks for this suggestion :)
Almost the same: https://www.codewars.com/kata/59146f7b4670ba520900000a
Wouldn't say that. It is a lower case password and here it is a PIN. It is more difficult to generate a passlist with letters. It's also SHA1 and not md5, but that isn't a big difference.
The Kata you posted was actually my idea to expand this one here.
Thanks for the link; but it's true that if you solved that one, you can basically copy-paste your solution here (with a few minor changes)
So, its almost a duplicate.
Maybe it's a nice little challenge before yours. I didn't see your kata and it wasn't also in the suggested duplicates so I thought it's unique. It is my first kata so it's fun to translate it in many languages and see the solutions of you (better programmer than me) :) Have a nice evening guys
Input validation is a worthless requirement, and having multiple return types is bad - remove this.
OK, i saw that in many other Katas, but i will remove it soon, if u guys say that it's worthless...
There is no input validation anymore
Too little random tests. Also, no random tests have the an answer of
False
. Or at least a very slim percentage. Need to increase chances of gettingFalse
as an aswer.Ok, I will fix that soon.
Added more random tests and there is no input validation anymore
C isn't even a language provided of this kata.
I'm working on C at the moment. Didn't publish it yet.
Why marked resolved? Shouldn't it only be resolved after zLuki releases the C version?
Now I've published the C version, so it's fine that the issue is marked as resolved :)
In python, you also return "false" as a string. It should be
False
. Example tests are also broken, as missing parentheses and false is the output. It isFalse
. Also, missing parentheses in the last example test.You are right. I fixed it now. Thanks for writing this comment :)
Nope. Still not. Change
false
toFalse
.and also "false" to False. Python uses False.
Are you sure? On my end it is corrected...
Forgot to reset. you are right.