Giter Site home page Giter Site logo

pypass's People

Contributors

nanak avatar truh avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pypass's Issues

Eigener transcoder

Hab schnell mal einen transcoder für die unterschiedlichen Zahlensysteme geschrieben.
Der Vorteil ist das es damit sehr leicht möglich währe das der Benutzer selber festlegen kann wie das Passwort encoded werden soll, also welche Zeichen im Passwort vorkommen sollen.

BASE64_DIGITS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

BASE16_DIGITS = '0123456789ABCDEF'

BASE2_DIGITS = '01'

# Decodes an encoded number into a decimal number.
# 
# data ... the encoded number (string)
# source ... the system the number is encoded in (string)
def decode(data, source):
    value = 0
    for d in data:
        if d in source:
            value = value * len(source)
            value = value + source.find(d)
    return value

# Encodes a decimal number into system given by target
#
# data ...  number that should be encoded
# target ... system the number should be encoded to
def encode(data, target):
    result = ''
    while int(data) > 0:
        r = int( data % len(target) )
        result = target[r] + result
        data = data / len(target)
    return result

# Transcodes a number from one numeric system to another.
# For examples to see how a 'system' should look like, take a
# look at the constants BASE64_DIGITS, BASE16_DIGITS (hexadecimal),
# string.digits (decimal), string.octdigits (octal)
# and BASE2_DIGITS (binary)
# 
# Unsigned numbers only since the '-' character could also be 
# used as a digit. 
#
# All the parameters should be Strings!
#
# data ... number that should be transcoded
# target ... target system the number should be encoded to
# source ... system the number is currently encoded in
#
def transcode(data, target, source):
    return encode( decode( data, source ), target )

Wollt das halt lieber nochmal mit dir absprechen bevor ich den einbaue.

Verwenden könnte man das ganze etwa folgender maßen:

import encode
# hex -> Base64
print encode.transcode('AFFE123456789', encode.BASE64_DIGITS, encode.BASE16_DIGITS)

# dezimal in irgendein willkürliches encoding
print encode.transcode('9999998887', '?_:D-O.o', '0123456789')

Hab jetzt noch nicht wirklich getestet ob die Ergebnis auch stimmen, sieht soweit aber nicht schlecht aus.

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.