Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21145
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <arnodel@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'python': 0.08; 'filename': 0.09; 'def': 0.13; 'received:209.85.214.174': 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; 'received:10.60': 0.16; 'cc:addr:python-list': 0.16; 'this:': 0.16; 'subject:skip:d 10': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'written': 0.19; "haven't": 0.20; 'checked': 0.21; 'cc:no real name:2**0': 0.21; 'header:In- Reply-To:1': 0.22; 'runs': 0.23; 'index': 0.24; 'guess': 0.26; 'cc:2**0': 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; 'message-id:@mail.gmail.com': 0.29; "skip:' 10": 0.29; 'cc:addr:python.org': 0.29; 'url:)': 0.29; 'actually': 0.31; 'skip:( 20': 0.31; "i've": 0.32; 'break': 0.32; 'file': 0.34; 'try:': 0.34; 'received:209.85.214': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'should': 0.38; 'received:209': 0.39; '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; 'jul': 0.93 |
| Received-SPF | pass (google.com: domain of arnodel@gmail.com designates 10.60.4.202 as permitted sender) client-ip=10.60.4.202; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of arnodel@gmail.com designates 10.60.4.202 as permitted sender) smtp.mail=arnodel@gmail.com; dkim=pass header.i=arnodel@gmail.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eTzJq+s337X40pgSfwehAPPNot6PTqKOcQlkzoMqWeM=; b=BJ5W7eHR64Xht0wLEXElfGZQ3dGCJvEvJBRWkUUU5lWmPIYf5tooW+d1+D5+od6WlE vY+enjWlIh/7uRWHYfDSvfZX5xcrmhN9fl4gpgiWZYI1GTJR1d7qi+l3i1tKUQQhQqnr A+1A6Sx1Rw3SGNXoRwRVIpru796jbIZEB4DY51biBwb4I+cHo/DTjX8RJgR+pXp8mZch RuM7YUyhI8bDUdXDMf+AgFzJOTGH14fk4NcnKFA3GN3isueX7HLmvh3xxqoP0dGjFixk gQTgJht0JG1EBd7RFu0eUa6TSgt857OhZyDNwjQLZliIP5zxwAShMvifoLN3FjXGb6wf a9gg== |
| MIME-Version | 1.0 |
| In-Reply-To | <CAFRczdMaSSi2KnFy0fEF2PBpTacVThd3ESD0mVT2MfaLvgHAgg@mail.gmail.com> |
| References | <CAFRczdMaSSi2KnFy0fEF2PBpTacVThd3ESD0mVT2MfaLvgHAgg@mail.gmail.com> |
| Date | Fri, 2 Mar 2012 20:18:56 +0000 |
| Subject | Re: decompilation |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| To | shikha panghal <spdollyshikha4@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list@python.org |
| 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.351.1330719539.3037.python-list@python.org> (permalink) |
| Lines | 190 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330719539 news.xs4all.nl 6901 [2001:888:2000:d::a6]:51649 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21145 |
Show key headers only | View raw
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 :)
--
Arnaud
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: decompilation Arnaud Delobelle <arnodel@gmail.com> - 2012-03-02 20:18 +0000
csiph-web