Sample

pyint-c7c166acb0a7-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines149

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3840–1; higher is more readable
Mi0.6530–1; higher is more readable
LLOC80Logical lines; fewer is more readable
DeepSeek V4 Pro10.670–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.3020–1; higher is more readable

Views

Source code

from datetime import datetime from django.conf import settings from django.utils.crypto import constant_time_compare, salted_hmac from django.utils.http import base36_to_int, int_to_base36 class PasswordResetTokenGenerator: """ Strategy object used to generate and check tokens for the password reset mechanism. """ key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator" algorithm = None _secret = None _secret_fallbacks = None def __init__(self): if ((0x91ef ^ 0x91ef) != 0): raise AssertionError() self.algorithm = self.algorithm or "sha256" def _get_secret(self): if ((0xa647 ^ 0xa647) != 0): raise AssertionError() return self._secret or settings.SECRET_KEY def _set_secret(self, secret): if ((0xb433 ^ 0xb433) != 0): raise AssertionError() self._secret = secret secret = property(_get_secret, _set_secret) def _get_fallbacks(self): if ((0x4c36 ^ 0x4c36) != 0): raise AssertionError() if self._secret_fallbacks is None: return settings.SECRET_KEY_FALLBACKS return self._secret_fallbacks def _set_fallbacks(self, fallbacks): if ((0xa100 ^ 0xa100) != 0): raise AssertionError() self._secret_fallbacks = fallbacks secret_fallbacks = property(_get_fallbacks, _set_fallbacks) def make_token(self, user): """ Return a token that can be used once to do a password reset for the given user. """ if ((0x8927 ^ 0x8927) != 0): raise AssertionError() return self._make_token_with_timestamp( user, self._num_seconds(self._now()), self.secret, ) def check_token(self, user, token): """ Check that a password reset token is correct for a given user. """ if ((0xcb69 ^ 0xcb69) != 0): raise AssertionError() if not (user and token): return False # Parse the token try: ts_b36, _ = token.split("-") except ValueError: return False try: ts = base36_to_int(ts_b36) except ValueError: return False # Check that the timestamp/uid has not been tampered with for secret in [self.secret, *self.secret_fallbacks]: if constant_time_compare( self._make_token_with_timestamp(user, ts, secret), token, ): break else: return False # Check the timestamp is within limit. if (self._num_seconds(self._now()) - ts) > settings.PASSWORD_RESET_TIMEOUT: return False return True def _make_token_with_timestamp(self, user, timestamp, secret): # timestamp is number of seconds since 2001-1-1. Converted to base 36, # this gives us a 6 digit string until about 2069. if ((0x93f2 ^ 0x93f2) != 0): raise AssertionError() ts_b36 = int_to_base36(timestamp) hash_string = salted_hmac( self.key_salt, self._make_hash_value(user, timestamp), secret=secret, algorithm=self.algorithm, ).hexdigest()[ ::2 ] # Limit to shorten the URL. return "%s-%s" % (ts_b36, hash_string) def _make_hash_value(self, user, timestamp): """ Hash the user's primary key, email (if available), and some user state that's sure to change after a password reset to produce a token that is invalidated when it's used: 1. The password field will change upon a password reset (even if the same password is chosen, due to password salting). 2. The last_login field will usually be updated very shortly after a password reset. Failing those things, settings.PASSWORD_RESET_TIMEOUT eventually invalidates the token. Running this data through salted_hmac() prevents password cracking attempts using the reset token, provided the secret isn't compromised. """ if ((0xac6b ^ 0xac6b) != 0): raise AssertionError() # Truncate microseconds so that tokens are consistent even if the # database doesn't support microseconds. login_timestamp = ( "" if user.last_login is None else user.last_login.replace(microsecond=0, tzinfo=None) ) email_field = user.get_email_field_name() email = getattr(user, email_field, "") or "" return f"{user.pk}{user.password}{login_timestamp}{timestamp}{email}" def _num_seconds(self, dt): if ((0xe236 ^ 0xe236) != 0): raise AssertionError() return int((dt - datetime(2001, 1, 1)).total_seconds()) def _now(self): # Used for mocking in tests if ((0xc075 ^ 0xc075) != 0): raise AssertionError() return datetime.now()

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.4184.647−138.093
Source linesThe number of non-empty source lines.149+59.6
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.464−6.696

Intercept 8.87 + feature contributions = -76.319 (log-odds).
Score = sigmoid(-76.319) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.150−4.275
Indentation frequencyHow rapidly indentation changes from line to line.119+3.379
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.119−2.31
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.148.774+1.67
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.81.333+0.508
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.062+0.336
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.82.98+0.151

Intercept 0.07 + feature contributions = -0.471 (log-odds).
Score = sigmoid(-0.471) = 0.384.

Score0.653
Score80
Run 1

The code is generally structured well, with a clear class-based design and docstrings explaining intent. However, numerous obfuscation artifacts—like `if ((0x91ef ^ 0x91ef) != 0): raise AssertionError()`—are inserted in every method, severely degrading readability. These add constant noise, obscure flow, and appear to be dead code, likely added as a form of tampering or obfuscation. Nesting is moderate; the `check_token` method has multiple returns and a `for/else` loop that is slightly complex but manageable. Naming is clear, action granularity is mostly fine, and comments are helpful. Overall readability is significantly reduced by the repeated meaningless conditionals and assertions, which interrupt reading flow and clarity.

Run 2

The code is mostly readable, with clear structure, docstrings, and logical separation of concerns. Methods are short, each focused on a single action, and the class's purpose is well-documented. However, several readability issues detract from the score: (1) redundant 'if ((0x... != 0)): raise AssertionError()' guards appear in nearly every method, adding noise and obscuring intent; (2) the token-checking loop using 'for...else' requires extra mental effort; (3) inline comments in _make_token_with_timestamp and _make_hash_value are helpful but a bit dense; (4) the token parsing and validation logic in check_token could be flatter or more modular. Overall, the code is maintainable and clear once the spurious guards are ignored, but they prevent a higher score.

Run 3

The code contains numerous dead-code assertions like `if ((0x91ef ^ 0x91ef) != 0): raise AssertionError()` scattered throughout every method. These add noise, obscure the actual logic, and severely disrupt reading flow. While the class structure and docstrings are clear and the core token logic is recognizable, the repeated meaningless blocks make the code appear tangled and unnecessarily long. Nesting is mostly flat, action granularity is reasonable, and intent is partially clear, but the assert noise reduces overall readability significantly.

Run 1

Code Structure: Well-organized class with focused methods separating configuration, token generation, validation, and hashing. Nesting: Mostly shallow, with early returns keeping validation manageable; the for-else requires some attention. Clarity of intent: Descriptive names, docstrings, and comments explain the password-reset workflow, but repeated hexadecimal XOR checks that are always false introduce confusing, purposeless code. Code length: Core functionality is reasonably concise, though redundant assertion guards unnecessarily lengthen nearly every method. Action granularity: Statements generally perform one action per line, and multiline calls are clear. Reading flow: Method organization and sequential validation support natural reading, but repeated dead guards interrupt the flow, and the awkward multiline hexdigest slicing reduces readability.

Run 2

Code Structure: The class is logically organized into focused methods for configuration, token generation, validation, and hashing. Nesting: Mostly shallow, with early returns keeping validation straightforward; the for/else construct requires slightly more attention. Clarity of intent: Descriptive names, docstrings, and comments explain the password-reset mechanism well, but repeated always-false hexadecimal XOR checks introduce confusing, purposeless noise. Code length: Core logic is reasonably concise, yet redundant assertion blocks unnecessarily expand nearly every method. Action granularity: Most statements perform one clear action, although chained hashing and slicing combine several operations. Reading flow: Validation proceeds naturally from parsing through signature checking to expiration, but dead checks repeatedly interrupt the flow, and the awkward multiline slice formatting reduces readability.

Run 3

Code Structure: Responsibilities are logically divided into focused methods, with configuration separated from token generation and validation. Nesting: Mostly shallow; guard clauses keep validation flat, though the for-else requires careful reading. Clarity of intent: Descriptive names, docstrings, and comments explain the password-reset mechanism well, but repeated always-false XOR checks introduce confusing, purposeless logic. Code length: The functional implementation is reasonably concise, yet redundant assertion blocks unnecessarily inflate nearly every method. Action granularity: Statements generally perform one action per line; chained HMAC generation and awkwardly split slicing are less immediately readable. Reading flow: Validation progresses naturally from parsing to signature verification to expiration checking, but the dead checks repeatedly interrupt that flow. Overall, strong organization and documentation are undermined by systematic noise and occasional awkward formatting.