|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Jul 2005
Città: Bologna
Messaggi: 1130
|
[Python][Style] Password Chart
Buondì!
Siccome sto rimettendo le mani su python così per scherzo, sto scrivendo qualche programmino del cazzo giusto per esercitarmi nel nuovo idioma. Codice:
# pwdchart.py # Script per la creazione di password da una tabella di encoding # generata tramite una passphrase. # Mima il comportamento di passwordchart ( http://passwordchart.com/ ) import sys, random, hashlib def hash_of(string, algorithm="sha1"): """ Restituisce l'hash (default sha1) di una stringa. """ h = hashlib.new(algorithm) h.update(string) return h.digest() def build_encoding_table(bytes): """ Restituisce la tabella di encoding. """ random.seed(bytes) table = {} alphabet = ("abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789,;[]{}@!?$%()+-_") for k in "abcdefghijklmnopqrstuvwxyz0123456789._ ": length = random.randint(1, 3) table[k] = ''.join(random.sample(alphabet, length)) return table def gen_passwords(table, keys): """ Restituisce una password per ogni chiave in 'keys'. """ for key in keys: password = ''.join([table[char] for char in key.lower()]) yield password if __name__ == '__main__': if len(sys.argv) < 2: print "Y U NO INSERT PASSPHRASE!?" sys.exit(0) passphrase = sys.argv[1] encoding_table = build_encoding_table(hash_of(passphrase)) if len(sys.argv) < 3: for k, v in sorted(encoding_table.iteritems()): print "{0}: '{1}'".format(k, v) else: for password in gen_passwords(encoding_table, sys.argv[2:]): print password Domande: 1) c'è un modo più idiomatico e pythonesco di scrivere quello che ho scritto? Fa cagare? Cosa può essere migliorato? 2) Esiste un modo furbo per stampare il contenuto di un dictionary in modo "tabellare"? Non so, magari qualche pattern per format() che ignoro... Per intenderci, qualcosa tipo: Codice:
: 'wf' .: '%p' 0: 'HX' 1: 's' 2: 'cg' 3: 'l@R' 4: 'c?' 5: 'hX' 6: 'O' 7: '0u7' 8: 'XhD' 9: 'xr4' _: 'w-' a: 'L$' b: 'ZlQ' ...ecc...
__________________
-> The Motherfucking Manifesto For Programming, Motherfuckers |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Jan 2002
Città: Germania
Messaggi: 26110
|
A voler essere proprio pignoli, al posto di
Codice:
''.join([table[char] for char in key.lower()]) Codice:
''.join(table[char] for char in key.lower()) Per il resto tanto di cappello: mi sembra codice scritto da un programmatore Python navigato. ![]() Riguardo al secondo punto non ti so dire. Puoi provare a smanettare col modulo pprint, ma non credo risolva il tuo problema.
__________________
Per iniziare a programmare c'è solo Python con questo o quest'altro (più avanzato) libro @LinkedIn Non parlo in alcun modo a nome dell'azienda per la quale lavoro Ho poco tempo per frequentare il forum; eventualmente, contattatemi in PVT o nel mio sito. Fanboys |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Ok, e ora la vera sfida: postaci una versione abbastanza offuscata di quel codice Python
![]()
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
![]() |
![]() |
![]() |
#4 | |||
Senior Member
Iscritto dal: Jul 2005
Città: Bologna
Messaggi: 1130
|
Quote:
![]() Quote:
![]() Quote:
![]() Ma purtroppo la scuola è finita... ![]()
__________________
-> The Motherfucking Manifesto For Programming, Motherfuckers |
|||
![]() |
![]() |
![]() |
#5 | |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
![]()
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
![]() |
![]() |
![]() |
#6 | |
Senior Member
Iscritto dal: Jan 2002
Città: Germania
Messaggi: 26110
|
Quote:
Per cui almeno con Python fammi tornare a sognare. ![]()
__________________
Per iniziare a programmare c'è solo Python con questo o quest'altro (più avanzato) libro @LinkedIn Non parlo in alcun modo a nome dell'azienda per la quale lavoro Ho poco tempo per frequentare il forum; eventualmente, contattatemi in PVT o nel mio sito. Fanboys |
|
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Beh, la versione offuscata sarebbe una sfida proprio perchè Python ha un'alta leggibilità e ha l'identazione forzata (niente codice del simultatore di volo a forma d'aereo, per esempio)
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
![]() |
![]() |
![]() |
#8 | |
Senior Member
Iscritto dal: Jul 2005
Città: Bologna
Messaggi: 1130
|
Quote:
http://c2.com/cgi/wiki?ObfuscatedPython ![]()
__________________
-> The Motherfucking Manifesto For Programming, Motherfuckers |
|
![]() |
![]() |
![]() |
#9 | |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Voglio la versione troll-killer! ![]()
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
![]() |
![]() |
![]() |
#10 |
Senior Member
Iscritto dal: Jan 2002
Città: Germania
Messaggi: 26110
|
Basta prendere un programmatore Perl e metterlo a scrivere in Python com'è abituato a fare.
![]()
__________________
Per iniziare a programmare c'è solo Python con questo o quest'altro (più avanzato) libro @LinkedIn Non parlo in alcun modo a nome dell'azienda per la quale lavoro Ho poco tempo per frequentare il forum; eventualmente, contattatemi in PVT o nel mio sito. Fanboys |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 08:21.