Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21151
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <kliateni@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'python': 0.08; '>>>>': 0.09; 'filename': 0.09; 'def': 0.13; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '.py': 0.16; '3.2.1': 0.16; '[gcc': 0.16; 'except:': 0.16; 'file.close()': 0.16; 'lose.': 0.16; '\xe9crit': 0.16; 'received:74.125.82.44': 0.16; 'received:mail-ww0-f44.google.com': 0.16; 'this:': 0.16; 'subject:skip:d 10': 0.17; 'wrote:': 0.18; 'written': 0.19; "haven't": 0.20; 'checked': 0.21; 'header:In-Reply-To:1': 0.22; 'cheers': 0.23; 'runs': 0.23; 'index': 0.24; 'guess': 0.26; 'code.': 0.26; 'module': 0.26; 'code': 0.26; 'skip:[ 10': 0.27; 'import': 0.27; 'random': 0.28; 'url:code': 0.28; 'invalid': 0.28; 'pass': 0.29; "skip:' 10": 0.29; 'url:)': 0.29; 'pretty': 0.31; 'message-id:@gmail.com': 0.31; 'actually': 0.31; 'skip:( 20': 0.31; "i've": 0.32; 'break': 0.32; 'header:User-Agent:1': 0.33; 'file': 0.34; 'try:': 0.34; 'to:addr:python-list': 0.35; 'received:74.125.82': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'received:192': 0.38; 'received:74.125': 0.38; 'should': 0.38; 'to:addr:python.org': 0.40; 'type': 0.61; 'header:Received:6': 0.61; 'more': 0.61; 'your': 0.61; 'march': 0.61; 'url:p': 0.62; 'reply': 0.64; 'choice.': 0.64; 'here': 0.64; 'skip:w 40': 0.67; 'was:': 0.67; 'lost': 0.68; '4.2.1': 0.84; 'action:': 0.84; 'received:10.180': 0.84; 'received:192.168.0.1': 0.84; 'jul': 0.93 |
| Received-SPF | pass (google.com: domain of kliateni@gmail.com designates 10.180.80.40 as permitted sender) client-ip=10.180.80.40; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of kliateni@gmail.com designates 10.180.80.40 as permitted sender) smtp.mail=kliateni@gmail.com; dkim=pass header.i=kliateni@gmail.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=ijw6PkyV3MSSAwfoD8JwBDuvd6+V0XlYjU+3eWQAvo4=; b=mTy3nianY/CiCKyyjt7fo3qd+JB/TLLKj9scwwr3RBgHxGXHvkx8EQEQrY+vB14f5T GHbLgDbfoL8otyvqjpQlS6LnO6XtDtWBzKIIVYfPkfiiKs/l11E2i8vtXP2S5b74wVMR uiKXe79g6kPU6YVue+HID/FqvPtr6zyKtkvstzG0iIBX8o02a7NQv9n5Vdct3I6iNbHR L+wyTBaGGarQ4q9/TjAh8oGsA0RJ3S5+4uut2eiFUksP4TXSfuXX2s66xjpDecYrWLcZ hWvJyW6ULozI0F1KOX5LH5oVTabmHrv/pYrigQMS/xUFlLRKdPUQAL6sBZgeNfxiBesK 0PcA== |
| Date | Fri, 02 Mar 2012 22:57:12 +0100 |
| From | Karim <kliateni@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: decompilation |
| References | <CAFRczdMaSSi2KnFy0fEF2PBpTacVThd3ESD0mVT2MfaLvgHAgg@mail.gmail.com> <CAJ6cK1b28HTCKi7m6A=d-m8T8erqnYJ1MEnCVtM36qoL=WUoMA@mail.gmail.com> |
| In-Reply-To | <CAJ6cK1b28HTCKi7m6A=d-m8T8erqnYJ1MEnCVtM36qoL=WUoMA@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.356.1330725435.3037.python-list@python.org> (permalink) |
| Lines | 193 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330725435 news.xs4all.nl 6914 [2001:888:2000:d::a6]:60273 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21151 |
Show key headers only | View raw
Le 02/03/2012 21:18, Arnaud Delobelle a écrit :
> On 2 March 2012 18:52, shikha panghal<spdollyshikha4@gmail.com> wrote:
>> Hi
>>
>> Please decoplile the .pyc code ,as i have lost my .py code.
> Aha, a customer! I've written a module for this: unpyc3
> (http://code.google.com/p/unpyc3/)
>
> Here it is in action:
>
>
> Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import unpyc3
>>>> import hangman322
>>>> code = unpyc3.decompile(hangman322)
>>>> print(code)
> import random
>
> def readFile(fileName):
> file = open(fileName)
> lineList = file.readlines()
> file.close()
> return lineList
>
> def initialize(fileName):
> try:
> lineList = readFile(fileName)
> except:
> print('Oops! ' + filename + ' was not a valid file.')
> return
> len_d = len(lineList)
> word_length = [0]*len_d
> for i in range(len_d):
> if lineList[i][-1] == '\n':
> word_length[i] = len(lineList[i]) - 1
> else:
> word_length[i] = len(lineList[i])
> tabulate = [0]*25
> for i in range(len_d):
> if word_length[i]>= 24:
> tabulate[24] = tabulate[24] + 1
> else:
> tabulate[word_length[i]] = tabulate[word_length[i]] + 1
> words = [None]*25
> for i in range(2, 24):
> words[i] = [None]*tabulate[i]
> k = 0
> for j in range(len_d):
> if word_length[j] == i:
> words[i][k] = lineList[j]
> k = k + 1
> for i in range(24, 25):
> words[i] = [None]*tabulate[i]
> k = 0
> for j in range(len_d):
> if word_length[j]>= i:
> words[i][k] = lineList[j]
> k = k + 1
> return words
>
> def wordsOfLength(n, source_file):
> words = initialize(source_file)
> return words[n]
>
> def getUserStringInput(L, prompt):
> replyInList = False
> while not replyInList:
> reply = input(prompt)
> replyInList = reply in L
> if not replyInList:
> print('That reply is invalid. Try again.')
> return reply
>
> def intListToStringList(L):
> L2 = ['']*len(L)
> for i in range(len(L)):
> L2[i] = str(L[i])
> return L2
>
> def getNewLetterGuess(availableLetters):
> letterString = ''
> for j in range(26):
> if availableLetters[j]:
> letterString = letterString + chr(65 + j) + ' '
> else:
> letterString = letterString + ' '
> validChar = False
> print(letterString)
> while not validChar:
> reply = input('Guess!> ')
> if len(reply) == 1:
> validChar = True
> letterIndex = ord(reply) - 65
> if letterIndex> 25:
> letterIndex = letterIndex - 32
> while letterIndex> 25 or not availableLetters[letterIndex]:
> print('This is an invalid choice. Please try again!')
> validChar = False
> print(letterString)
> while not validChar:
> reply = input('Guess!> ')
> if len(reply) == 1:
> validChar = True
> letterIndex = ord(reply) - 65
> if letterIndex> 25:
> letterIndex = letterIndex - 32
> guess = chr(97 + letterIndex)
> availableLetters[letterIndex] = False
> return guess, availableLetters
>
> def getWordFamilyCounter(L, n, guess):
> wordFamilyCounter = [0]*2**n
> familyIndexList = [-1]*len(L)
> for k in range(len(L)):
> w = list(L[k])
> ct = 0
> for k2 in range(n):
> if w[k2] == guess:
> ct = ct + 2**k2
> familyIndexList[k] = ct
> wordFamilyCounter[ct] = wordFamilyCounter[ct] + 1
> return wordFamilyCounter, familyIndexList
>
> def extractLargestFamily(L, familyIndexList, wordFamilyCounter):
> bestFamily = wordFamilyCounter.index(max(wordFamilyCounter))
> boolist = [False]*len(L)
> for k3 in range(len(L)):
> if familyIndexList[k3] == bestFamily:
> boolist[k3] = True
> j2 = 0
> smallList = [' ']*sum(boolist)
> for k4 in range(len(L)):
> if boolist[k4]:
> smallList[j2] = L[k4]
> j2 = j2 + 1
> return smallList
>
> def updatePatternList(patternList, guess, bestFamily):
> n = len(patternList)
> for k6 in range(n):
> if bestFamily//2 == bestFamily/2:
> pass
> else:
> patternList[k6] = guess + ' '
> bestFamily = bestFamily>> 1
> return patternList
>
> def pickWordFrom(L):
> index = random.randint(0, len(L) - 1)
> return L[index]
>
> def play():
> reply = getUserStringInput(intListToStringList(list(range(2,
> 21))), 'How long should I make your word?!!? (2 to 20)> ')
> n = int(reply)
> patternList = ['_ ']*n
> print(''.join(patternList))
> L = wordsOfLength(n, 'dictionary.txt')
> reply = getUserStringInput(intListToStringList(list(range(1,
> 27))), 'How many guesses will you need?> ')
> m = int(reply)
> availableLetters = [True]*26
> for i in range(m):
> guess, availableLetters = getNewLetterGuess(availableLetters)
> wordFamilyCounter, familyIndexList = getWordFamilyCounter(L, n, guess)
> bestFamily = wordFamilyCounter.index(max(wordFamilyCounter))
> if bestFamily == 0:
> print('Letter not in word.')
> else:
> print('Letter is in word!!!')
> L = extractLargestFamily(L, familyIndexList, wordFamilyCounter)
> patternList = updatePatternList(patternList, guess, bestFamily)
> print(''.join(patternList))
> if '_ ' not in patternList:
> break
> if '_ ' not in patternList:
> print('SURELY you must be CHEATING, but you guessed my word in
> ' + str(i + 1) + ' tries!!!')
> else:
> bogusWord = pickWordFrom(L)
> print('You lose. The word was: ' + bogusWord)
>
> I haven't actually checked if this code runs :)
>
Great code (unpy3) Arnaud!
pretty well built.
Cheers
Karim
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: decompilation Karim <kliateni@gmail.com> - 2012-03-02 22:57 +0100
csiph-web