Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #
- # Script par Guiroux Hugo
- import sys
- import getpass
- import struct
- def usage():
- print "Script par Guiroux Hugo pour le Pre-Magistere d'informatique.\n"
- class CarteMagnetique:
- deviceHandle = None
- data = None
- qwerty = False
- dictionnary = {unicode('à', 'utf-8') : '0',
- unicode('&', 'utf-8') : '1',
- unicode('é', 'utf-8') : '2',
- unicode('"', 'utf-8') : '3',
- unicode('\'', 'utf-8') : '4',
- unicode('(', 'utf-8') : '5',
- unicode('-', 'utf-8') : '6',
- unicode('è', 'utf-8') : '7',
- unicode('_', 'utf-8') : '8',
- unicode('ç', 'utf-8') : '9',
- unicode(':', 'utf-8') : ':',
- unicode('m', 'utf-8') : ';',
- unicode('§', 'utf-8') : '?'
- }
- def __init__(self):
- try:
- self.deviceHandle = sys.stdin
- except IOError as (errno, strerror):
- raise "Impossible d'ouvrir stdin ! (%s)" % strerror
- def __del__(self):
- if self.deviceHandle != None:
- self.deviceHandle.close()
- def lire(self):
- self.data = getpass.getpass("Veuillez passer votre carte...\n")
- decoded_string = ""
- if self.data[0] == 'm':
- self.qwerty = True
- for i in self.data.decode('utf-8'):
- if self.qwerty:
- decoded_string += self.qwertyToAzerty(i)
- else:
- decoded_string += i
- self.data = decoded_string
- def rawDump(self):
- if self.data == None:
- raise "Impossible d'afficher le dump, toujours pas de donnee !"
- print "-- Chaine : --"
- print self.data
- print "-- Fin de la chaine --\n"
- def clearDump(self):
- if self.data == None:
- raise "Impossible d'afficher le dump, toujours pas de donnee !"
- print "-- Chaine interprétée : --"
- interpreted_string = ""
- for i in self.data:
- if i == ";":
- interpreted_string += "{Start}"
- elif i == ":" or i == "<" or i == ">":
- interpreted_string += "{Controle}"
- elif i == "=":
- interpreted_string += "{Sep}"
- elif i == "?":
- interpreted_string += "{End}"
- else:
- interpreted_string += i
- print interpreted_string
- print "-- Fin de la chaine interprétée --\n"
- def decToBin(self, number, count = 24):
- return "".join([str((number >> y) & 1) for y in range(count-1, -1, -1)])
- def qwertyToAzerty(self, lettre):
- try:
- return self.dictionnary[lettre]
- except:
- pass
- return lettre
- usage()
- test = CarteMagnetique()
- while True:
- test.lire()
- test.rawDump()
- test.clearDump()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement