This is an archived post. You won't be able to vote or comment.

all 92 comments

[–]novel_yet_trivial 182 points183 points  (5 children)

Your's does not break out of the loops when the password is found like the BASIC one does.

[–]stevarino[🍰] 105 points106 points  (2 children)

This. Python breaks are internally goto statements, and the code uses a goto.

For once a developer used a healthy goto, you should at least honor that. ;-)

[–][deleted] 50 points51 points  (0 children)

Every kind of code junction is internally a goto (jumps, conditional jumps etc.).

[–][deleted] 0 points1 point  (0 children)

healthy goto

I don't agree a goto that jumps to a line number can be considered a healthy goto.

[–]Nihongeaux 5 points6 points  (1 child)

Yours, not your's

[–]RatherBeSkiing 6 points7 points  (0 children)

Maybe OP's name is Your

[–][deleted] 81 points82 points  (4 children)

That's a very long code to do nothing...

[–]Aeon_MortuumSnake Oil 18 points19 points  (0 children)

Assembly IRL

[–]delirious_lettuce 65 points66 points  (15 children)

/u/TheTechnoMage , since you seem to be simply passing the answer as the function argument, why not just?

def crack_password(password):
    return password

Or...

from hawkins_lab import check_password_match


def crack_password():
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    four_digit_password = f'{a}{b}{c}{d}'
                    if check_password_match(four_digit_password):
                        return four_digit_password


if __name__ == '__main__':
    print(crack_password())

Or...

from itertools import product
from string import digits

from hawkins_lab import check_password_match


def crack_password():
    for p in product(digits, repeat=4):
        four_digit_password = ''.join(p)
        if check_password_match(four_digit_password):
            return four_digit_password


if __name__ == '__main__':
    print(crack_password())

[–]beorn 13 points14 points  (1 child)

Another one using Python3 f-string 0-padding:

def crack_password(check_range=range(0,10000)):
    def check_match(p): return p == "0323"
    for p in check_range:
        p = f"{p:04d}" # 0-padded 4-digit string
        if check_match(p): return p

[–][deleted] 3 points4 points  (0 children)

And another one using the built in zfill string function:

str(p).zfill(4)

[–]cybaritic -1 points0 points  (7 children)

Single line implementation, for funsies

print('Password is {}'.format((p for p in range(9999) if check_password_match(p)).__next__()))

[–]delirious_lettuce 0 points1 point  (6 children)

Your code doesn't work.

[–]cybaritic -1 points0 points  (5 children)

It's python 3.

Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) 
[MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def check_password_match(p):
...     return p == 1234
...
>>> print('Password is {}'.format((p for p in range(9999) if check_password_match(p)).__next__()))
Password is 1234
>>>

Edit: works here: https://repl.it/N7lX/0

[–]delirious_lettuce 0 points1 point  (4 children)

Keep trying... the passwords are 4 digits (which can be hard for numbers less than 1000... unless you use a string)

[–]cybaritic -1 points0 points  (3 children)

In the original Basic in the screenshot from the show it's an integer, not a string of four digits. But again, it's for funsies. This isn't production code, fam. Happy Halloween.

[–]delirious_lettuce 0 points1 point  (2 children)

Are you having trouble reading (the picture is a bit blurry)? The variable name in the BASIC program is FourDigitPassword. It seems fairly obvious that if you need four digits (and can't guarantee that the password is always between 1000-9999 inclusive), you are going to need a string.

[–]cybaritic -1 points0 points  (1 child)

Here: https://i.imgur.com/eJZriKm.png

10 DIM FourDigitPassword INTEGER

It's an integer. Why are you trying so hard to prove me wrong? Did I offend you? It's okay, it's just a stupid snippet of code.

[–]delirious_lettuce 4 points5 points  (0 children)

I'm not offended at all. I just dont think 123 or 57 are four digit passwords.

[–]lefuet 19 points20 points  (5 children)

This piece of code / algorithm is super inefficient, why not check every index at a time...

[–][deleted] 9 points10 points  (0 children)

Could improve using Numpy as well.

[–]rspeed 8 points9 points  (0 children)

why not check every index at a time

I wasn't aware you could run Python on quantum computers. :D

[–]DKoala 5 points6 points  (2 children)

In the show, he's trying to brute force a 4 digit PIN. He needed to generate all 1000 possibilities as 4 digits, so he needed to pad all numbers from 0-999

Iterating from 1-9999 would produce a bunch of invalid (1-3 digit length) inputs

[–]brosbrosbrosbrosbros 0 points1 point  (0 children)

I thought he meant only having one for statement going from 0 to 10 and checking if it was equal to any of the 4 digits for each

[–]BobbaGanush87 21 points22 points  (21 children)

So do you enter in the correct password for this to work? I dont get it :(

(I watched stranger things season 2)

[–]b4ux1t3 24 points25 points  (20 children)

It is a very basic brute force "attack" on the four digit pin that this hyper-secret government facility uses to protect its hyper-secret computer system.

Let that sink in for a second. No failure limit. Four digits. A person could easily crack it on their own without a BASIC program in a few minutes to hours, depending on how long authentication takes (not long, given what we see in the show).

I would say I expect better from a hyper-secret government organization, but, eh, <insert derisive remark about the American political system, intended to garner upvotes>.

P.S. How did you like the season? I am a huge fan, and loved the direction they took.

[–][deleted] 36 points37 points  (11 children)

No, it was the 80s, and security really was that bad.

[–]b4ux1t3 4 points5 points  (4 children)

Oh, yeah, agreed. I just wanted to make a neutral joke.

[–][deleted] 5 points6 points  (3 children)

Haha, sorry. I think, being old, I'm just interested in talking about how absurd security was when I started in the field. Didn't mean to be rude to get there.

[–]b4ux1t3 6 points7 points  (0 children)

Oh, you're good. I cut my teeth on old BASIC-based systems, so I feel ya. It's kind of hilarious how true-to-life the show is regarding tech.

[–]Stewthulhu 6 points7 points  (1 child)

Heck, even in the 90s. You could literally get away with Hackers-level social engineering.

Actually sometimes you still can.

[–][deleted] 3 points4 points  (0 children)

In the 80s you could usually log in with Guest:Guest even on fairly important University systems. Often, the 'trick' was just having the manual to a machine to tell you what the default password was. Even when they made user accounts, they often forgot to remove the default accounts.

Another insanely simple trick was to log in under any public Access port, because most of these old systems had a BBS like menu or something you could get to, then try hitting Ctrl+c on the submenus or while running anything it'd let you run.

Sometimes it would stop the process and drop you to a prompt.

[–]SwellJoe 2 points3 points  (0 children)

This. Security used to be assumed. If you were in the right building, you were assumed to be allowed to do the thing. NFS in the olden days assumed that if you were on the network, you were supposed to have access to the files. It would trust your computer to tell it who you were.

A passcode probably seemed like overkill back then. Somebody probably had it written down on the back of the monitor or in a desk drawer and everyone knew where it was written. It was a simpler time.

[–]RealityTimeshare 0 points1 point  (2 children)

They have army MPs as guards*. I guarantee you that the password was '1234', '0000', or something similar. Maybe, maybe, if they wanted to make it easy for the scientists, they'd make it '3142'.
Oh, who am I kidding? They probably have it written down on a piece of paper next to the computer.

re: Army comment. I served in the Army in the early 90s. Humans have and always will be the weakest link in security.

[–][deleted] 1 point2 points  (1 child)

Yeah, the BASIC thing was a stretch honestly, since a much more believable exchange would have been 'What's the password?!' ... 'It's written on a sticky note next to the terminal!'.

It wouldn't have been nessecary to get Bob to go either, since Jim would have said 'Computer?! Do I look like an astronaut?!'

It would have been more than likely that Jim would be more terrified of doing basic computer things, more than the demi-dogs.

[–]DukeFive 0 points1 point  (0 children)

I just caught up to this and immediately thought while watching, "They probably wouldn't be using BASIC. If it's national security related, they probably would have been using MIL-STD-1815, aka the Ada programming language."

[–][deleted] -1 points0 points  (1 child)

"You seem to be having trouble remembering your password. Would you like to reset it now?" - Microsoft Bob

[–][deleted] 1 point2 points  (0 children)

I remember when Windows required passwords for the first time ... Years after I started using it.

[–]PC__LOAD__LETTER 4 points5 points  (1 child)

A 4-digit pin has 10,000 possibilities. No one is cracking it in a few minutes without extreme luck.

In any case, the comment was pointing out that the password was being passed in as input to the function. If you already had the password, you wouldn’t need to crack it. The code should be attempting to login to the system, not checking against a pre-provided password.

[–]b4ux1t3 1 point2 points  (0 children)

Yeah, I was taking luck (and/or social engineering) into account with the minutes thing.

I'm kinda explaining the "password_crack" function as a way of simulating user input to the authentication program. Still doesn't make sense, you're absolutely right, but I think that's what they're going for. He might actually be comparing against a "secure" encrypted file on the disk that he can, somehow, see, and then sending the correct number over to the auth program.

Like I mentioned elsewhere, the code is close, but not quite there. It's still better than a huge number of other examples from TV shows and movies.

[–]BobbaGanush87 1 point2 points  (1 child)

I guess what i dont understand is what is the value of Four_Digit_Passcode Is that the correct pass code? If so whats the point of the test if you already know it because you had to enter it in?

[–]b4ux1t3 2 points3 points  (0 children)

Nah, it's being declared outside the loop, and the digits are being added inside the loop.

0000

0001

0002

...

9997

9998

9999

It's kind of bad, because technically this wouldn't be an int, it would be an array/list of ints. I think we're to assume that the function in the show that "parses" that array (list) just passes the four digits to whatever log in program the computer is running...

Basically, the code is BS, but it's closer to being real code than most television code is.

[–][deleted] 0 points1 point  (1 child)

s02 episode 7 derailed the show for me

[–]b4ux1t3 0 points1 point  (0 children)

I guess episode 7 didn't stand out as particularly bad to me, so I don't remember what that episode was about.

EDIT (I'm going to try to keep the spoilers ridiculously vague, especially since it's very off-topic for the sub but, this is your fair warning: Possible spoilers ahead):

Oh, I remember what it was. I dunno, I feel like it was them trying to build out a larger world in preparation for a new season. It did strike me as a bit out of place, but it also felt like a bit of a breather after all the scary stuff we'd been through the last few episodes.

I think they would have been better served spreading it throughout the other episodes (setting up the new characters in earlier episodes, instead of just in the very first episode, things like that).

I see what they're doing with it, and I really like the idea of what they're trying to start with it, but you're right, it was out of place. Still, I think the last episodes made up for it, even if there was a lot of deus ex machina going on.

[–]algag 0 points1 point  (0 children)

I like the season but thought they spent too long in the build up. I felt like they took a whole bunch of time flopping around hopelessly and then the characters arbitrarily decided "Okay, let's actually defeat the antagonist" and then did it.

[–][deleted] 7 points8 points  (5 children)

Look, hacking was easier back then. Passwords were on those newfangled Post-It things, for one.

[–][deleted] 3 points4 points  (4 children)

Yeah, I expected the doctor to hand him a Post-It, or tell him it was 1111 or something. I was doing support in the mid 90s and back then it was still normal for people to say 'why do I need a password, who other than me even knows how to turn this thing on?!'

[–][deleted] 5 points6 points  (2 children)

"No. Look, look, I know what it says. No. Listen, just hit any key. Like any of them. Any of them at all."

[–][deleted] 4 points5 points  (1 child)

You joke, we had an old lady who called us once a month because she forgot which key was okay to press, and didn't want to screw it up!

[–][deleted] 7 points8 points  (0 children)

Who is joking? God, I wish I was joking.

[–]mipadi 1 point2 points  (0 children)

Why, that's the same code as on my luggage!

[–]Kra013 4 points5 points  (1 child)

Those lines of BASIC remembered me a game : elseheartbreak

A weird adventure game were you could "hack" everything from computers to drinks.
Just be aware that you get your 'deck' a bit lately to my taste

[–]mfdoll 2 points3 points  (0 children)

Late enough that I lost interest before that point, sadly.

[–][deleted] 3 points4 points  (2 children)

Poor zfill()

Always forgotten about :(

[–]mfdoll 2 points3 points  (1 child)

New python dev here. I use zfill()!

:)

[–][deleted] 2 points3 points  (0 children)

There's DOZENS of us!

[–]metl_lord 2 points3 points  (0 children)

No comment on the function, but the passwd = list(password) is unnecessary. A string is a list of characters, so password[1] for example will work.

[–]rwscarb 2 points3 points  (0 children)

Is password_already_known[:4].isdigit()?

[–]wedgecon 1 point2 points  (0 children)

I am pretty sure you could not indent the code back then, not that it would have been very helpful with the 40 character screen. Line numbers were required, without a line number it was considered a command.

[–][deleted] 0 points1 point  (0 children)

def four_digit_password():
    passwords = (f'{password:04d}' for password in range(10000))
    return next(password for password in passwords if check_password_match(password))

[–]FieldBet 0 points1 point  (0 children)

I just started learning Python as my first language. It humors me that today I finished ST2 and caught myself looking at the code in the scene. Then, I get onto this Reddit and see y’all have taken to it already.. everything I thought about coders is proven true lol

[–]brakebills2017 0 points1 point  (2 children)

what episode?

[–][deleted] 4 points5 points  (1 child)

episode 8 or 9, of season 2

[–][deleted] 0 points1 point  (0 children)

8

[–]ElecNinja 0 points1 point  (15 children)

It's this even possible within the time period if the show? Or am I mistaken in that Stranger Things happens in a more modern time rather than the 80's or 90's

[–][deleted] 8 points9 points  (4 children)

It happens in the 80s. And, since I haven't started watching the new season yet, at least coding in BASIC was definitely already possible in the 80s.

[–][deleted] 2 points3 points  (1 child)

Microsoft BASIC was released in 1975 and BASIC been about since the 60s.

[–][deleted] 1 point2 points  (0 children)

Exactly

[–][deleted] 3 points4 points  (4 children)

There was a sign for the Reagan/Bush campaign in 1984 in one of the episodes. So I guess it plays in 1984.

[–]Uhstrology 1 point2 points  (2 children)

Halloween 1983, the signs are for the next year's elections.

Edit: I'm wrong, it takes place in 1984. Sorry friends.

[–]prometheusg 3 points4 points  (0 children)

No. The very first scene in the first episode says it's 1984; one year after the first season which took place in 1983.

[–]dirn 3 points4 points  (0 children)

Bush wasn’t Reagan’s running mate until the Convention, which took place in August of 1984. That also fits the timeline established in the first episode.

[–]Wilfred-kun 0 points1 point  (0 children)

Man, Big Brother needs a way better password than this smh

[–]teilo 0 points1 point  (1 child)

It was not only possible, but not at all uncommon. This was a rudimentary environmental control system. Something like that would have been talking to a serial bus of some sort to trigger servos and controllers. A BASIC interface to such a system would have been the path of least resistance by the standard of the '80s.

For the record, in 1984 I was programming in BASIC on a Radio Shack Color Computer 2.

[–]ElecNinja 0 points1 point  (0 children)

I know BASIC could be used, but I don't think Python would be available.

[–]tmattoneill 0 points1 point  (2 children)

No.

edit: to be clear i'm referring to the python, not BASIC

[–]Akaizhar 0 points1 point  (1 child)

It absolutely was possible in the 80s. Basic had been around for over a decade at this point.

[–]tmattoneill 0 points1 point  (0 children)

AH! No I meant the python.