Source

wheezy.core / src / wheezy / core / feistel.py

""" ``feistel`` module.
"""


def make_feistel_number(f):
    """ Generate pseudo random consistent reversal number
        per Feistel cypher algorithm.

        see http://en.wikipedia.org/wiki/Feistel_cipher

        >>> feistel_number = make_feistel_number(sample_f)
        >>> feistel_number(1)
        573852158
        >>> feistel_number(2)
        1788827948
        >>> feistel_number(123456789)
        1466105040

        Reversable

        >>> feistel_number(1466105040)
        123456789
        >>> feistel_number(1788827948)
        2
        >>> feistel_number(573852158)
        1
    """
    def feistel_number(n):
        l = (n >> 16) & 65535
        r = n & 65535
        for i in (1, 2, 3):
            l, r = r, l ^ f(r)
        return ((r & 65535) << 16) + l
    return feistel_number


def sample_f(x):
    return int((((1366 * x + 150889) % 714025) * 32767) // 714025)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.