Git Product home page Git Product logo

stypr_crypt's Introduction

stypr_crypt's People

Contributors

stypr avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

stypr_crypt's Issues

`time.Now().UTC().UnixNano() + <delta>` can accidentally hit future time

Lol hi again !

While I was writing my SIP protocol fuzzer, I wrote some seed generation code that was very similar to your crypto.go:randInt() implementation:

// https://github.com/stypr/stypr_crypt/blob/master/crypto.go#L11-L14
func randInt(count int) int {
    rand.Seed(time.Now().UTC().UnixNano() + rand.Int63n(65537))
    return 1 + rand.Intn(count)
}

The issue is that adding random Δns (i.e. rand.Int63n(65537)) to the time.Now().UTC().UnixNano() to create a seed object and then creating another seed object in the future can actually create two identical deterministic seed objects if and only if you created the second object Δns + (second Δns) after creating the first object. Once the two time luckily hits the same time result, you get two identical and no-longer random seeds.

Although this is probably impossibly rare case in the wild, I remembered that you had a similar implementation when I read your crypto.go back in 2016. I think you said this repo is not for production but I wanted to let you know since I thought it was pretty cool! 😄

collisions

Hello~

I think your implementation looks so cool (especially the C code) that I had to take a closer look~ After some random tests, k (https://github.com/initbar/stypr_crypt/blob/master/crypto.py#L5) might need a different generation (other than random.randint(1, 1024)).

screen2

I think the problem is that since the random pool is coded with tight bounds (1024), a collision can occur as little as 38 iterations. However, weird thing is that even with a small tweak (above) to increase the upper bound from 1024 to 2**32, it seems like I can always hit a collision within <2048 iterations (most certainly at 2048 - 1).

Since stypr_encrypt('a') predictably generates a length 10 block (+6 with additional characters), using the relationship between length and additional characters, an assumption can be safely made that length 10 block must contain only 1 character (and 16 == 2 characters, etc.). Which, even if the stypr_decrypt() wasn't available, since exhausting all blocks with length 1 (i.e. [A-Za-z0-9]) is super fast (based on the implementation), I think finding a collision and asserting that the plaintext found without proper decryption is computationally feasible (code below):

from crypto import * # stypr's crypto

def get_collision(k):
  H = []
  a = k
  r = 2048
  for i in xrange(r):
    H.append(stypr_encrypt(a)[4:10][::-1])
    if len(set(H)) < i: break
  return i

print get_collision('a')

Result:

screen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.