This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2012-02-23 18:22:25

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Python Official Topic

This is the secret message:

Code:

231039119174222085007179032046174036079006248051046168036095007244038115105222053249179056125176222077006248222129160036085002250222119175234012013003052046168052095008179042124170054012011251032130091051084248179042115180222085007193222085170046080179253046112092

This is the working code:

Code:

# Asterik Encryption v1.7
# By Magnie
# Credit if used. :D

def crypt(text, key):
    # This takes the ascii value of each letter of the key then adds them all together,
    # then it multiplies that by the length of the key.
    kord = sum([ord(x) for x in key]) * len(key)
    cipher_text = ''
    
    #i is used to alternate through each letter of the key and use it's ascii value.
    i = 0
    for x in text: # For each letter in the plain_text
        # Multiply key[i] by length of the text then add the kord value to it then
        # add the ascii value of letter 'x'
        cipher_letter = ord(x) + (kord + ord( key[i] ) * len(text))
        
        # Make sure the letter is less than 255
        cipher_letter %= 255
        cipher_letter = str(cipher_letter) # Make it a string
        
        # Make sure each value is in a 3 letter chunk. So if the value is 9, change it
        # to 009.
        while len(cipher_letter) != 3:
            # Add a zero to the front
            cipher_letter = '0'+cipher_letter
        # Add the number to the end of the cipher_text
        cipher_text += cipher_letter
        
        # Switch to the next letter in the key.
        i = (i+1) % len(key)
    
    # Return the cipher_text to the script.
    return int(cipher_text)

def decrypt(text, key):
    try:
        number = int(text) # Is it crypted text? Since crypted text is only numbers
        kord = sum([ord(x) for x in key]) * len(key)
        plain_text = []
    except ValueError:
        return 'Not encrypted.'
    
    cipher_chunk = ''
    i = 0
    for x in text:
        cipher_chunk += x
        i = (i+1) % 3
        if i == 0:
            plain_text.append(cipher_chunk)
            cipher_chunk = ''

    decrypted = ''
    i = 0
    for x in plain_text:
        decrypt = int(x) - (kord + ord( key[i] ) * len(plain_text))
        while decrypt < 0:
            decrypt += 255
        decrypted += chr(decrypt)
        i = (i+1) % len(key)
    
    return decrypted
            
        

if __name__ == "__main__":
    while True:
        text = raw_input("Text: ")
        key = raw_input("Key: ")
        type = raw_input("(E)ncrypt or (D)ecrypt: ")
        if type.lower() == 'e':
            print crypt(text, key)
        elif type.lower() == 'd':
            #for i in xrange(97, 122):
                #key = chr(i)
            print decrypt(text, key)

CheeseMonkey: The encryption code for the other one didn't encrypt the message correctly. Making it virtually impossible to decrypt.  tongue

Last edited by Magnie (2012-02-23 18:24:03)

Offline

 

#27 2012-02-23 18:28:05

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: Python Official Topic

Magnie wrote:

CheeseMunchy: The encryption code for the other one didn't encrypt the message correctly. Making it virtually impossible to decrypt.  tongue

big_smile
ya I mentioned that it the encrypter I used before was different.
Here, does this work?:
=:##{1<_:6_*3[<_:6_*3[444

Last edited by CheeseMunchy (2012-02-23 18:34:10)


6418,

Offline

 

#28 2012-02-23 19:33:23

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Python Official Topic

CheeseMunchy wrote:

Magnie wrote:

CheeseMunchy: The encryption code for the other one didn't encrypt the message correctly. Making it virtually impossible to decrypt.  tongue

big_smile
ya I mentioned that it the encrypter I used before was different.
Here, does this work?:
=:##{1<_:6_*3[<_:6_*3[444

I meant on my encryption code. The only problem with the decrypter you gave me was that periods were s's and commas were r's.

Offline

 

#29 2012-07-04 06:05:15

NZPrograms
Scratcher
Registered: 2012-06-12
Posts: 14

Re: Python Official Topic

I am just starting with scratch, so if anyone could tell me some basics, that would be very appreciated.

Offline

 

#30 2012-07-04 07:00:06

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Python Official Topic

NZPrograms wrote:

I am just starting with scratch, so if anyone could tell me some basics, that would be very appreciated.

Why are you posting this in the Python topic? Scratch and Python are 2 completely different things! I suggest you ask in the Help with Script forum, as there are many Scratchers out there willing to help you.  smile


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#31 2012-07-06 02:44:37

NZPrograms
Scratcher
Registered: 2012-06-12
Posts: 14

Re: Python Official Topic

SciTecCf wrote:

NZPrograms wrote:

I am just starting with scratch, so if anyone could tell me some basics, that would be very appreciated.

Why are you posting this in the Python topic? Scratch and Python are 2 completely different things! I suggest you ask in the Help with Script forum, as there are many Scratchers out there willing to help you.  smile

So sorry, I meant python.  tongue

Offline

 

#32 2012-08-07 17:00:13

playzooki
Scratcher
Registered: 2012-02-07
Posts: 100+

Re: Python Official Topic

Please help this does not work!
code:

import random
dn = 1
l = 2
   
while dn == 1:
   print " I am thinking of a number between 1 and" , l, ", which number is it"
   t = for i in xrange(1):
    yield random.randint(1, l)
    r = input("answer:")
    if r == t:
        print "Correct"
        l = l+1
    else:
        print "Wrong"
        print "your score was" ,l-1, "points. Thanks for playing!"
        dn = 0
    What did I do wrong?


I iz a sig. So there. CLICK ME ITS SO IMPORTANT!!!!

Offline

 

#33 2012-08-07 17:08:55

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Python Official Topic

playzooki wrote:

Please help this does not work!
code:

import random
dn = 1
l = 2
   
while dn == 1:
   print " I am thinking of a number between 1 and" , l, ", which number is it"
   t = for i in xrange(1):
    yield random.randint(1, l)
    r = input("answer:")
    if r == t:
        print "Correct"
        l = l+1
    else:
        print "Wrong"
        print "your score was" ,l-1, "points. Thanks for playing!"
        dn = 0
    What did I do wrong?

What error did you get?

Offline

 

#34 2012-08-07 20:39:18

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Python Official Topic

playzooki wrote:

Please help this does not work!
code:

import random
dn = 1
l = 2
   
while dn == 1:
   print " I am thinking of a number between 1 and" , l, ", which number is it"
   t = for i in xrange(1):
    yield random.randint(1, l)
    r = input("answer:")
    if r == t:
        print "Correct"
        l = l+1
    else:
        print "Wrong"
        print "your score was" ,l-1, "points. Thanks for playing!"
        dn = 0
    What did I do wrong?

Python 2 or 3?

Offline

 

#35 2012-08-09 16:12:35

playzooki
Scratcher
Registered: 2012-02-07
Posts: 100+

Re: Python Official Topic

2.7.2, invalid syntax on for (for was highlighted)

Last edited by playzooki (2012-08-11 14:45:04)


I iz a sig. So there. CLICK ME ITS SO IMPORTANT!!!!

Offline

 

#36 2012-11-30 12:17:34

Gravitation
New Scratcher
Registered: 2012-09-26
Posts: 500+

Re: Python Official Topic

Bump!

I got bored.  tongue

Code:

import pygame, sys, random
from pygame.locals import *
pygame.init()
amountOfParticles = 150
pygame.key.set_repeat(1000/30, 1000/30)
particles = []
DISPLAYSURF = pygame.display.set_mode((800, 600), 0, 32)
pygame.display.set_caption('Christmas Particles')
for i in range(amountOfParticles):
    particles.append([random.randint(1, 799), random.randint(1, 599), random.randint(-1, 1), random.randint(-1, 1), random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)])
while True:
    DISPLAYSURF.fill((0, 0, 0))
    for i in range(len(particles)):
        pygame.draw.polygon(DISPLAYSURF, (particles[i][4], particles[i][5], particles[i][6]), [(particles[i][0], particles[i][1]), (particles[i][0]+1, particles[i][1]), (particles[i][0]+1, particles[i][1]+1), (particles[i][0], particles[i][1]+1)])
        pygame.draw.polygon(DISPLAYSURF, (particles[i][4], particles[i][5], particles[i][6]), [(800 - particles[i][0], particles[i][1]), (800 - particles[i][0]+1, particles[i][1]), (800 - particles[i][0]+1, particles[i][1]+1), (800 - particles[i][0], particles[i][1]+1)])
        pygame.draw.polygon(DISPLAYSURF, (particles[i][4], particles[i][5], particles[i][6]), [(particles[i][0], 600 - particles[i][1]), (particles[i][0]+1, 600 - particles[i][1]), (particles[i][0]+1, 600 - particles[i][1]+1), (particles[i][0], 600 - particles[i][1]+1)])
        pygame.draw.polygon(DISPLAYSURF, (particles[i][4], particles[i][5], particles[i][6]), [(800 - particles[i][0], 600 - particles[i][1]), (800 - particles[i][0]+1, 600 - particles[i][1]), (800 - particles[i][0]+1, 600 - particles[i][1]+1), (800 - particles[i][0], 600 - particles[i][1]+1)])
        particles[i][0] += particles[i][2]
        particles[i][1] += particles[i][3]
        particles[i][2] *= 0.999
        particles[i][3] *= 0.999
        if particles[i][0] > 799 or particles[i][0] < 1:
            particles[i][2] *= -1
        if particles[i][1] > 599 or particles[i][1] < 1:
            particles[i][3] *= -1
        particles[i][4] = (particles[i][4] + 1) % 256
        particles[i][5] = (particles[i][5] + 1) % 256
        particles[i][6] = (particles[i][6] + 1) % 256
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    if pygame.mouse.get_pressed()[0] == True:
        for i in range(len(particles)):
            xdist = particles[i][0] - pygame.mouse.get_pos()[0]
            ydist = particles[i][1] - pygame.mouse.get_pos()[1]
            if xdist > 0:
                particles[i][2] -= 0.01
            else:
                particles[i][2] += 0.01
            if ydist > 0:
                particles[i][3] -= 0.01
            else:
                particles[i][3] += 0.01
    pygame.display.update()

Offline

 

#37 2013-02-04 17:22:45

MrFlash67
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: Python Official Topic

I am currently learning Python 3.3. Unfortunately, I cannot get it to install on this school computer. I must copy the files onto my flash drive and transfer them to my account.


Who would win, SOPA or PIPA?

Offline

 

Board footer