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

#1 2012-01-25 22:06:00

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Python Official Topic

Discuss Python. What are you making in it? what do you need to learn? if so, ask about it!


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#2 2012-01-25 22:06:31

Freakish
Scratcher
Registered: 2011-10-25
Posts: 1000+

Re: Python Official Topic

I'm not the programming type.


http://i.imgur.com/y3RBV.jpg

Offline

 

#3 2012-01-25 22:07:13

Agentpieface
Scratcher
Registered: 2009-10-10
Posts: 1000+

Re: Python Official Topic


http://media.tumblr.com/tumblr_lr7fywSZAG1qfj8fq.gif

Offline

 

#4 2012-01-26 16:19:53

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

Re: Python Official Topic

I'm sort of developing Soulite which is a Pygame module to keep the Scratch feel of things in Python!  big_smile

Offline

 

#5 2012-01-27 16:25:34

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

Re: Python Official Topic

I've been experimenting with Pyscripter a little lately.


6418,

Offline

 

#6 2012-01-27 16:51:17

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

Re: Python Official Topic

Agentpieface wrote:

Stick to the first topic

I believe that was the second topic.  tongue
----------------------------------------------------------

I'm making translator, and in order to make it I need my program to replace text.
Say I wanted to only replace 5s with 1s and not 55s when I say

variable.replace ("5","1")

I'm a noob to Pyscripter, so can someone tell me how to do that?

Last edited by CheeseMunchy (2012-01-27 22:48:27)


6418,

Offline

 

#7 2012-01-27 16:55:15

Agentpieface
Scratcher
Registered: 2009-10-10
Posts: 1000+

Re: Python Official Topic

CheeseMunchy wrote:

Agentpieface wrote:

Stick to the first topic

I believe that was the second topic.  tongue
----------------------------------------------------------

No, look at the date of the first posts.

Stick to the first topic!

tongue


http://media.tumblr.com/tumblr_lr7fywSZAG1qfj8fq.gif

Offline

 

#8 2012-01-27 16:59:39

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

Re: Python Official Topic

Agentpieface wrote:

CheeseMunchy wrote:

Agentpieface wrote:

Stick to the first topic

I believe that was the second topic.  tongue
----------------------------------------------------------

No, look at the date of the first posts.

Stick to the first topic!

tongue

Well if you can get it moved here from Misc, we'll use it.  tongue


6418,

Offline

 

#9 2012-01-27 17:08:02

Agentpieface
Scratcher
Registered: 2009-10-10
Posts: 1000+

Re: Python Official Topic

CheeseMunchy wrote:

Agentpieface wrote:

CheeseMunchy wrote:

I believe that was the second topic.  tongue
----------------------------------------------------------

No, look at the date of the first posts.

Stick to the first topic!

tongue

Well if you can get it moved here from Misc, we'll use it.  tongue

yeah, just realised it's in misc

when i said stick to the first topic misc was still up and running  tongue

Last edited by Agentpieface (2012-01-27 17:08:36)


http://media.tumblr.com/tumblr_lr7fywSZAG1qfj8fq.gif

Offline

 

#10 2012-01-27 22:46:49

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

Re: Python Official Topic

Bump, anyone who can answer my question?  hmm


6418,

Offline

 

#11 2012-01-27 23:48:47

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

Re: Python Official Topic

CheeseMunchy wrote:

Bump, anyone who can answer my question?  hmm

Code:

>>> variable = '51515'
>>> variable
'51515'
>>> variable.replace('5', '1')
'11111'
>>> variable
'51515'
>>> variable.replace('1', '5')
'55555'

or

Code:

variable = '51515'
print variable
print variable.replace('5', '1')
print variable.replace('1', '5')

Offline

 

#12 2012-01-28 00:08:03

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

Re: Python Official Topic

Magnie wrote:

CheeseMunchy wrote:

Bump, anyone who can answer my question?  hmm

Code:

>>> variable = '51515'
>>> variable
'51515'
>>> variable.replace('5', '1')
'11111'
>>> variable
'51515'
>>> variable.replace('1', '5')
'55555'

or

Code:

variable = '51515'
print variable
print variable.replace('5', '1')
print variable.replace('1', '5')

While I was trying to explain my question more clearly to you, in a quote I wrote before this, I answered it for myself by accident. But thanks for getting me thinkin' Magnie. ^^

Last edited by CheeseMunchy (2012-01-28 00:09:43)


6418,

Offline

 

#13 2012-01-28 00:57:31

yomomma21
New Scratcher
Registered: 2012-01-24
Posts: 51

Re: Python Official Topic

I tried using it with blender awhile back. My brain still hurts ._.

Offline

 

#14 2012-02-22 22:40:04

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

Re: Python Official Topic

I made my own language!
I dare you too decrypt it. ^^

_:._*3[<_:._*3[1<_=*.<*.<,>_=:,<+)3"<=>><*_<({)#/<-:<@,:__~<+,:>%*3[<=>,/<_{</:|,~@_<_=*."<=>=>=><}~<#>3[)>[:<*.<=*//:3<+,{}<}{/.<({{_2

Last edited by CheeseMunchy (2012-02-22 22:49:27)


6418,

Offline

 

#15 2012-02-22 22:53:11

zippynk
Scratcher
Registered: 2011-07-23
Posts: 500+

Re: Python Official Topic

CheeseMunchy wrote:

I made my own language!
I dare you too decrypt it. ^^

Code:

_:._*3[<_:._*3[1<_=*.<*.<,>_=:,<+)3"<=>><*_<({)#/<-:<@,:__~<+,:>%*3[<=>,/<_{</:|,~@_<_=*."<=>=>=><}~<#>3[)>[:<*.<=*//:3<+,{}<}{/.<({{_2

Well, according to google, there is no way to find out.

Also, what does this have to do with python?

P.S. I had to put your thing in a code tag because scratch confused it with code from the old block plugin.

Last edited by zippynk (2012-02-22 22:54:05)


https://dl.dropbox.com/u/60598636/trifocal_interlude_soundcloud_button.png

Offline

 

#16 2012-02-22 23:13:14

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

Re: Python Official Topic

CheeseMunchy wrote:

I made my own language!
I dare you too decrypt it. ^^

_:._*3[<_:._*3[1<_=*.<*.<,>_=:,<+)3"<=>><*_<({)#/<-:<@,:__~<+,:>%*3[<=>,/<_{</:|,~@_<_=*."<=>=>=><}~<#>3[)>[:<*.<=*//:3<+,{}<}{/.<({{_2

You have to give the source-code of the encryption. Cause without the algorithm, it's nearly impossible to decode for newbies like us in the forums.

Another reason people might not crack your ciphertext is that you haven't provided enough of it. It only takes a moment's thought to realise that the more ciphertext the attacker has, the easier it is for him to attack it. Giving would-be attackers just a little ciphertext and then crowing when they can't/don't crack it may be fun, but if you then draw the conclusion that your cipher is attack-proof, you could just end up in trouble if you start to trust it to protect lots of data. Consider, for example, a simple polyalphabetic cipher - give the attacker six bytes of plaintext, and he'll ignore it as a waste of time. Give him sixty bytes, though, and he might just crack it. Give him six hundred, and he'll crack it easily. And even a simple letter to a friend could easily take up a thousand or more bytes.

Yet another reason that some people might not crack your ciphertext is that you haven't explained how the algorithm works. Now, some people have the not unreasonable notion that keeping the algorithm secret improves security. Oddly enough, though, it doesn't. (There is an exception to this rule which I'll come to in a minute, which turns out not to be an exception after all.) Here's why a secret algorithm damages security:

As we have seen, it is sometimes possible to figure out key aspects of the algorithm just by inspecting the ciphertext. For example, a frequency analysis can generally tell us whether a monoalphabetic cipher has been used, or perhaps a transposition cipher. A Kasiski attack can show us whether a simple polyalphabetic cipher is in use. So, just because you don't tell people what the algorithm is, that doesn't necessarily mean they can't figure it out anyway.

If your cipher is more complex, though, it may not be possible to decrypt your ciphertext without knowing the algorithm in advance; but consider this: if it's that complicated, you've almost certainly written a computer program to do the encryption and decryption. So anyone who cares enough about your ciphertext can get at the algorithm, even if it means breaking into your home and ghosting your hard disk whilst you're out shopping or at work or at school or something. If that sounds like overkill, it just means you can't think of any reason why anyone would care enough to do it - which, for most if not all of us - is probably fair enough. Nevertheless, if you have BIG secrets to hide, your level of "justifiable paranoia" ought to increase in proportion.

If it matters enough, people will find out. The British, for example, managed to get hold of the design of the military version of the Enigma machine because the French found a guy in the Chiffrierstelle in 1931 (when Germany was not at war) who was prepared to sell them some vital documents which made this design clear; the French didn't care enough to do anything about it, so they gave it to the Poles, who made lots of progress against Enigma before they ran out of time and handed all they had to the British. So trying to keep your algorithm secret doesn't actually work. Indeed, the Germans realised this. In their security assessments of Enigma, they rightly started with the basic assumption that the enemy (the British) would find a way to get hold of an Enigma machine.

http://s13.zetaboards.com/Crypto/topic/123696/1

Last edited by Magnie (2012-02-22 23:16:24)

Offline

 

#17 2012-02-23 16:30:07

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

Re: Python Official Topic

Magnie wrote:

CheeseMunchy wrote:

I made my own language!
I dare you too decrypt it. ^^

_:._*3[<_:._*3[1<_=*.<*.<,>_=:,<+)3"<=>><*_<({)#/<-:<@,:__~<+,:>%*3[<=>,/<_{</:|,~@_<_=*."<=>=>=><}~<#>3[)>[:<*.<=*//:3<+,{}<}{/.<({{_2

You have to give the source-code of the encryption. Cause without the algorithm, it's nearly impossible to decode for newbies like us in the forums.

Another reason people might not crack your ciphertext is that you haven't provided enough of it. It only takes a moment's thought to realise that the more ciphertext the attacker has, the easier it is for him to attack it. Giving would-be attackers just a little ciphertext and then crowing when they can't/don't crack it may be fun, but if you then draw the conclusion that your cipher is attack-proof, you could just end up in trouble if you start to trust it to protect lots of data. Consider, for example, a simple polyalphabetic cipher - give the attacker six bytes of plaintext, and he'll ignore it as a waste of time. Give him sixty bytes, though, and he might just crack it. Give him six hundred, and he'll crack it easily. And even a simple letter to a friend could easily take up a thousand or more bytes.

Yet another reason that some people might not crack your ciphertext is that you haven't explained how the algorithm works. Now, some people have the not unreasonable notion that keeping the algorithm secret improves security. Oddly enough, though, it doesn't. (There is an exception to this rule which I'll come to in a minute, which turns out not to be an exception after all.) Here's why a secret algorithm damages security:

As we have seen, it is sometimes possible to figure out key aspects of the algorithm just by inspecting the ciphertext. For example, a frequency analysis can generally tell us whether a monoalphabetic cipher has been used, or perhaps a transposition cipher. A Kasiski attack can show us whether a simple polyalphabetic cipher is in use. So, just because you don't tell people what the algorithm is, that doesn't necessarily mean they can't figure it out anyway.

If your cipher is more complex, though, it may not be possible to decrypt your ciphertext without knowing the algorithm in advance; but consider this: if it's that complicated, you've almost certainly written a computer program to do the encryption and decryption. So anyone who cares enough about your ciphertext can get at the algorithm, even if it means breaking into your home and ghosting your hard disk whilst you're out shopping or at work or at school or something. If that sounds like overkill, it just means you can't think of any reason why anyone would care enough to do it - which, for most if not all of us - is probably fair enough. Nevertheless, if you have BIG secrets to hide, your level of "justifiable paranoia" ought to increase in proportion.

If it matters enough, people will find out. The British, for example, managed to get hold of the design of the military version of the Enigma machine because the French found a guy in the Chiffrierstelle in 1931 (when Germany was not at war) who was prepared to sell them some vital documents which made this design clear; the French didn't care enough to do anything about it, so they gave it to the Poles, who made lots of progress against Enigma before they ran out of time and handed all they had to the British. So trying to keep your algorithm secret doesn't actually work. Indeed, the Germans realised this. In their security assessments of Enigma, they rightly started with the basic assumption that the enemy (the British) would find a way to get hold of an Enigma machine.

http://s13.zetaboards.com/Crypto/topic/123696/1

Yup. ^^

Last edited by CheeseMunchy (2012-02-23 16:30:18)


6418,

Offline

 

#18 2012-02-23 16:35:07

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

Re: Python Official Topic

zippynk wrote:

CheeseMunchy wrote:

I made my own language!
I dare you too decrypt it. ^^

Code:

_:._*3[<_:._*3[1<_=*.<*.<,>_=:,<+)3"<=>><*_<({)#/<-:<@,:__~<+,:>%*3[<=>,/<_{</:|,~@_<_=*."<=>=>=><}~<#>3[)>[:<*.<=*//:3<+,{}<}{/.<({{_2

Well, according to google, there is no way to find out.

Also, what does this have to do with python?

P.S. I had to put your thing in a code tag because scratch confused it with code from the old block plugin.

I made the encrypter in python.


6418,

Offline

 

#19 2012-02-23 17:07:17

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

Re: Python Official Topic

CheeseMunchy wrote:

zippynk wrote:

CheeseMunchy wrote:

I made my own language!
I dare you too decrypt it. ^^

Code:

_:._*3[<_:._*3[1<_=*.<*.<,>_=:,<+)3"<=>><*_<({)#/<-:<@,:__~<+,:>%*3[<=>,/<_{</:|,~@_<_=*."<=>=>=><}~<#>3[)>[:<*.<=*//:3<+,{}<}{/.<({{_2

Well, according to google, there is no way to find out.

Also, what does this have to do with python?

P.S. I had to put your thing in a code tag because scratch confused it with code from the old block plugin.

I made the encrypter in python.

Could you post the encryption code?  smile

Offline

 

#20 2012-02-23 17:28:31

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

Re: Python Official Topic

Magnie wrote:

CheeseMunchy wrote:

zippynk wrote:


Well, according to google, there is no way to find out.

Also, what does this have to do with python?

P.S. I had to put your thing in a code tag because scratch confused it with code from the old block plugin.

I made the encrypter in python.

Could you post the encryption code?  smile

You mean the program?


6418,

Offline

 

#21 2012-02-23 17:44:11

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

Re: Python Official Topic

CheeseMunchy wrote:

Magnie wrote:

CheeseMunchy wrote:


I made the encrypter in python.

Could you post the encryption code?  smile

You mean the program?

Yes.  smile

Offline

 

#22 2012-02-23 18:00:01

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

Re: Python Official Topic

Magnie wrote:

CheeseMunchy wrote:

Magnie wrote:

Could you post the encryption code? :)

You mean the program?

Yes. :)

:O
My code mustn't be uncovered!
:p


Ohh, very well...

Code:

plott = raw_input("Well?")
satt = plott.replace (',','1')
dogo = satt.replace ('?','"')
var = dogo.replace ('.','4')
thebegginning = var.replace ('!','2')
a = thebegginning.replace ('a','>')
b = a.replace('b','-')
c = b.replace('c','|')
d = c.replace('d','/')
e = d.replace('e',':')
f = e.replace('f','+')
g = f.replace('g','[')
h = g.replace('h','=')
i = h.replace('i','*')
j = i.replace('j','^')
k = j.replace('k','%')
l = k.replace('l','#')
m = l.replace('m','}')
n = m.replace('n','3')
o = n.replace('o','{')
p = o.replace('p','@')
q = p.replace('q',';')
r = q.replace('r','5')
s = r.replace('s','6')
t = s.replace('t','_')
u = t.replace('u',')')
v = u.replace('v','&')
w = v.replace('w','(')
x = w.replace('x','$')
y = x.replace('y','~')
z = y.replace('z','`')

zett = z = z.replace(' ','<')

print plott
print zett

Oh ya, and the stuff I posted above I used my old faulty system so it won't work well.

Last edited by CheeseMunchy (2012-02-23 18:15:32)


6418,

Offline

 

#23 2012-02-23 18:14:52

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

Re: Python Official Topic

Yeah, your code is a simple substitution cipher. This one is mine:

Code:

91140218033068201122039133145033137195121108152145033137206123108146212019082128080109068234029153128122108137145034140201122051068234029153128110124137228033137196039123140214205148193122122155224032136128106118150227019135212115128069145244147207107039142224016069

Code:

# Asterik Encryption v1.6
# 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':
            print decrypt(text, key)

It's more of a shift-cipher. Oh well.

Edit: Hmm, actually, it's not working.  hmm

Last edited by Magnie (2012-02-23 18:17:58)

Offline

 

#24 2012-02-23 18:17:28

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

Re: Python Official Topic

Magnie wrote:

Yeah, your code is a simple substitution cipher. This one is mine:

Code:

911402180330682011220391331450331371951211081521450331372061231081462120190821280801090682340291531281221081371450341402011220510682340291531281101241372280331371960391231402142051481931221221552240321361281061181502270191352121151280691452
44147207107039142224016069

Code:

# Asterik Encryption v1.6
# 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':
            print decrypt(text, key)

It's more of a shift-cipher. Oh well.

Yaaa. I'm not quite ready to make something like that. :pp
However. I shall get to work on a new language, a much better one.

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


6418,

Offline

 

#25 2012-02-23 18:19:50

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

Re: Python Official Topic

Magnie wrote:

Edit: Hmm, actually, it's not working.  hmm

What isn't working?


6418,

Offline

 

Board footer