ov3rcl0ck 25 Junior Poster

You should use modules like pickle or marshal to serialize and load your datas...

I really agree with jice, but keep in mind the Pickle module shouldn't be used for anything that would requires good security, theres a good amount of exploitable loop holes that will most likely never be fixed, and are extremely easy to exploit.

ov3rcl0ck 25 Junior Poster

Using a standard library may allow your software to be cross-platform or easier to port to another platform. I'd say stick with the standard library, it'll be much easier and keep everything OO.

Ancient Dragon commented: agree. +25
ov3rcl0ck 25 Junior Poster

I'm using codepad.org to host my code so I can work on it at home, school or where ever theres a computer.

Check it out:
http://savethehouse.codepad.org/

All my pastes are currently private, so you won't see much, but I'll be opening it publicly soon.

ov3rcl0ck 25 Junior Poster

TKinter doesn't give a very native look or feel, I recommend WXpython, it can use GTK themes, or have a windows look.

But if you insist on using TKinter I can help you with that also, but I recommend that you check this out http://www.wxpython.org/tutorial.php

Right now I'm working on a python based, crossplatform(and portable) remake of rsync. It will give the ability to back up permissions, owner, zip/gzip/tar the files for more compact storage, and provide multiprocessor support.

ov3rcl0ck 25 Junior Poster

Hot damn, why such and odd Variable name? Just name it weight or something simple, I'm pretty sure you can't use "{" or "}" in a variable name.

ov3rcl0ck 25 Junior Poster

What are you aiming to get out of this? What is your end result?

ov3rcl0ck 25 Junior Poster

I'll check it out. Maybe help out with the multiprocessor support.

ov3rcl0ck 25 Junior Poster

... since Mac are realy running shiny Linux/BSD it should work there to.

Mac OS X is based around Darwin UNIX, a version of UNIX that derived from NEXTSTEP, which derived from BSD. OS X Contains no BSD code nor NEXTSTEp code anymore.

ov3rcl0ck 25 Junior Poster

If you set up some sort of source code repos I'd be happy to help, otherwise I could just post some code here or PM it to you.

ov3rcl0ck 25 Junior Poster

Maybe instead of using rsync, you can implement your own crossplatform version of rsync. You could also multithread is and/or use the multiprocessing module to provide multiple CPU support so copying can go much faster.

Another good idea is to make a daemon out of it, and have it backup to a certain source at given times every so often. Consider using wxpython for GUI, and docking the daemon on the system tray. It would be pretty sweet.

ov3rcl0ck 25 Junior Poster

Recoding never hurts, usually the first things I do to optimize codes is replace all range() funstions with xrange(), then I look for loops that can be replaced with lambda, then I look for if statments that can be changed to elif so it doesn't have to go over unnecessary if statments, then i look for regex functions that can be replaced with faster string functions, and finally i see if i can compact the code into less lines and less characters to allow faster interpreting and making it more sleek and compact.

ov3rcl0ck 25 Junior Poster

Right now i have used time for my input. Could you please give a bit more info on used memory and mouse movement?

Fetching memory usage and mouse input are OS dependent. There isn't a library to fetch memory usage, but you can use the "mem" command on windows to fetch it, and the "ps" or "free" command on UNIX to fetch it, but keep in mind you might need to use a little regex or at least some string functions. For mouse input you can use pyHook for windows, and xlib for UNIX(OS X supports X11, and any Unix distro worth using supports it).

If you need me to I can post some examples of pyHook, xlib, and memory fetching.

ov3rcl0ck 25 Junior Poster

Not quite sure what to mean...

ov3rcl0ck 25 Junior Poster

open it in binary mode. In unix however binary mode isn't needed but using 'wb' or 'rb' instead of 'w' or 'r' doesn't hurt. This should copy the file contents of a file to another no matter the content:

fi=open("filein", 'rb').read()
fo=open("fileout",'wb')
fo.write(fi)
fo.close()

In windows you just gotta use the 'rb'/'wb' flags to read the file contents as binary.

ov3rcl0ck 25 Junior Poster

Well there are several algorithms to generate random number, simplest to my knowledge being Linear congruential generator(LCG).

The general formula for LCG is X_{n+1} = \left( a X_n + c \right)~~\bmod~~m . The recommended value for a, m, c are given in Wikipedia page. It is recommended use those combinations of a, m, c for more randomness. Start with any value of X and for different random numbers everytime you run code choose X using system time.

To get number in particular range, eg [L, H) apply this to every random number generated(say Y) : Z = L + Y%(H-L)

Probably the best inputs is date/time, used memory, random user input, and my favorite mouse movement(truecrypt uses this).

ov3rcl0ck 25 Junior Poster

Buddy you are not using enough functions, if you need everything in one function(sometimes teachers require this) you can declare functions within a function but it gets pretty messy.

ov3rcl0ck 25 Junior Poster

You basically just give it a password and your done, you could read the manual that came with it, try a google search. It would give you a better answer than anyone here could.

ov3rcl0ck 25 Junior Poster

Not a bad idea, however as you said, not very secure. So if used for legit uses it could compromise the clients privacy, however SSL/TSL could fix this.

ov3rcl0ck 25 Junior Poster

WEP is very unsecure, it can be cracked in minutes, sometimes seconds. You should really go with WPA/2.

ov3rcl0ck 25 Junior Poster

Well it looks like you may be opening the file wrong, i don't know why is raising that error, you're not even using a list object. Try this:

import MySQLdb, csv, sys
conn = MySQLdb.connect (host = "localhost",user =
"a", passwd = "b",db = "c")
c = conn.cursor()
csv_data = csv.reader(file('TxtFile1.txt'))
for row in csv_data: print row
row = csv_data.next()
c.execute("INSERT INTO a (Category, Value) VALUES (%s, %s)", row)
#c.commit()
#c.close()

I believe this should work, if not post back and we can try something else.

ov3rcl0ck 25 Junior Poster

Wow thats a mess of code, try sorting some stuff into functions to make a little more clear first off, I can take a look at it later. Also I'd move the portion where you select your player name out before the loop so you don't have to set it again after every loop.

ov3rcl0ck 25 Junior Poster

I want to send it via email, but I haven't really played with the smptlib.
I might just use raw sockets instead. FTP was another way I thought, but I don't really know much about it. I don't have access to the internet too often, and when I do its for class. So research is mostly limited to the docs that came with python lol.

FTP is quite simple, you can make a 15 line program to upload the logs to a FTP server.

ov3rcl0ck 25 Junior Poster

I did something similar except I made 2 versions, one put the logs on a FTP server, one emailed the log. You could also try your hands at a linux keylogger, jut use xorg's xlib.

ov3rcl0ck 25 Junior Poster

oh no,you just cant understand, ok,i explain once again when you run py program its open ONE console, and i want to open ONE ---ANOTHER--- CONSOLE.

well then try this for windows, remember to launch it in its own process/thread though:

import os
os.system("python YOURSCRIPT.py")

or try this for linux:

import os
os.system("xterm python YOURSCRIPT.py")

for linux you need to launch a new terminal/shell otherwise it is run in the background.

ov3rcl0ck 25 Junior Poster

Amazon has a pretty large range of books and ebooks.

ov3rcl0ck 25 Junior Poster

2.6 has many bugs so i prefer 2.5

2.6 has been out for a while now, its pretty safe to use.

ov3rcl0ck 25 Junior Poster

Multiprocessing and threading are fairly similar, in fact multiprocessing is based off the multithreading API. Heres a really really easy example:

from multiprocessing import Process

def f(name):
    print 'hello', name

if __name__ == '__main__':
    p = Process(target=f, args=('bob',)) #inits thread
    p.start() #starts thread
    p.join() #waits untill thread is done
ov3rcl0ck 25 Junior Poster

Multi processing is similar to threading, google "python multiprocess"

ov3rcl0ck 25 Junior Poster
import threading
 
class THREAD(threading.Thread):
	def __init__(self,ARG1,ARG2):
		threading.Thread.__init__(self)
		#If you change the arugments of __init__ modify the bellow also
		self.arg1=ARG1
		self.arg2=ARG2
	def run(self):
		print "RUN"
		#THIS IS WERE YOUR CODE GOES!
ARG1,ARG2=1,2

t=THREAD(ARG1,ARG2)
t.start()
t.join()

Forgot a line. But you do realize this is an example and i posted it so you can adjust it to your needs, if you don't understand it you're not ready for threading, so this script probably won't work, and if it does its not gonna do anything.If you don't understand it you're not ready for threading.

Dixtosa commented: thx +0
ov3rcl0ck 25 Junior Poster

Gribouillis

and where can i donwload thatmodule?

gerard4143
2:D


ov3rcl0ck
I want to have that processes running on another thread and ability to continue doing something else.:)
and
I DONT want just to execute that little script then after it finishes it moves on. :)

ov3rcl0ck, for example, i have code:


...commands1...
...commands2...
call to t.py and imediately go on next command3
...commands3...
...commands4...

and i think separate process is the best in this time :)

First off Subprocess is a default module for python, next subprocess doesn't spawn a new thread, you need the multithreading module that comes default with the interpreter, also knowing object orientated programming will help. Try this little example:

import threading

class THREAD(threading.Thread):
	def __init__(self,ARG1,ARG2):
		#If you change the arugments of __init__ modify the bellow also
		self.arg1=ARG1
		self.arg2=ARG2
	def run(self):
		#THIS IS WERE YOUR CODE GOES!

t=THREAD(ARG1,ARG2)
t.start()
t.join()

The easiest way to do it is make a thread out of a function but this will lose alot of functionality and is a messy way of doing things IMO. Here it is:

import threading,thread

def THREAD(ARG1,ARG2):
	#YOUR CODE
thread.start_new_thread(THREAD, (ARG1,ARG2))
ov3rcl0ck 25 Junior Poster

I think it cannot hurt to know how a char array works. In my opinion it is something that you should know if you want to become better in C++ programming. And honestly I don't think that Mark knew how to use a char array.

But I agree. A string is easier to use than a char array. But I never said it would be easier with a char array.

He's probably in a class, its best not to get ahead of yourself, let him learn at his own pace.

ov3rcl0ck 25 Junior Poster
#include<iostream>
using namespace std;


int main()

{
    char name;
    int counter;
    
    
    
while (name!="stop")
{
      cout<<"Enter your friend's name (""stop"" to quit): ";
    cin>>name;
      
      cout<<"so you have"<<counter <<"\n\n";
counter ++;
}
cout<<"Go Make some friends you emotional loser!\n";    
    
    
    
    
    
    
    
    
    
      system ("pause") ;
  return 0;
}

In my opinion the cleanest way to do this is just have the user return a blank line when they're done. So "while (name!='')" would do that.

ov3rcl0ck 25 Junior Poster

you're not making much sense... Do you want to have that processes running on another thread so you can continue doing something else? Do you just want to execute that little script then after it finishes it moves on? What are you trying to do EXACTLY?

ov3rcl0ck 25 Junior Poster

Oh an another thing to try is CD to the program files, then call os.system

os.chdir("C:/Program Files/Winamp")
os.system("Winamp.exe")
ov3rcl0ck 25 Junior Poster

Its actually not as tough as people are making it out to be, if you have a space you need to put ' ' or " " around it to clarify that it has a space, maybe try this:

import os
os.system("'C:\Winamp\Winamp.exe'")

I may be wrong, i might have just been using Linux too long :P

ov3rcl0ck 25 Junior Poster

*Sigh* I don't know if you can't read, or you just skipped some posts, but this isn't supposed to be really complex. I don't know how fast brute force is, but IMO 60 to the power of the amount of characters in the message is a lot of combinations. But another thing that I don't know you understand, is that most people won't have the source code, because it would be on a USB (oh duh!, of course....) If I wanted to do an encryption, giving the source code would be like giving the code to the vault. The final result would just be a lonely string sitting in a text file. You can't expect to have the engine running and the source code.

Well either you're completely ignorant, or you have haven't put much thought into this. If someones in the position in which they can take your encrypted files then they could potentially steal your script, and in seconds they could crack it, i can make a loop that can input ever number from 1-9,000,000,000,000 in under a minute.

ov3rcl0ck 25 Junior Poster

Encryption does not have to be so complex and mathematical and what not. I can easily conceive that this would be considered a small encryption by many standards. This is not meant to stop white hat's by no means whatsoever, this is just a rather simple idea to keep the average person to read a personal message. No offense taken :). As for Vegaseats message, I won't need to decrypt the message if I have the encryption code. Another thing I would like to add, is that encryption is not necessarily defined as to how complex it is, but as to what it does.

Encryption complexity does mater, because your encryption can be solved with a bruteforce in under 5 min, what i could do is create a for loop that loops up to whatever number and inputs that into your algo, have it do a regex to find anything that could be english, once thats found i have the message, cracked with a simple 15 line scripts. Its almost pointless to make it, but i won't deny that it is a OK project to start your adventure down the road of cryptography. Personally my first experience with cryptography was making a MD5 hash cracker, I'd recommend that you try something like that.

ov3rcl0ck 25 Junior Poster

Since you don't know the specific error class, simply use ...

for i in range(1, 638):
    try:
        temp=start+str(i)
        permlist.append(str(url.urlopen(temp).readlines()[88]))
        textlist.append(str(url.urlopen(temp).readlines()[77]))
    except: # catch any exception and continue the for loop
        print "Error at index %d."%i
        pass

My bad i used the wrong exception, vegaseat is right.

ov3rcl0ck 25 Junior Poster

True raw_input does give you a string but converting is is extremely simple, also you can make it return a int/float if you want by doing this

d=int(raw_input("Input numer: "))

or for floats

d=float(raw_input("Input number: "))

but keep in mind that if the user inputs anything other than a intergers a exception with be raised, so be sure to use exeptions if you use this method.

ov3rcl0ck 25 Junior Poster

The way i see most fit is having it take input(intergers only) until the user enters a blank line, like so:

numbers=[]
print "Enter your numbers and enter a blank line when done \n\n"
while True:
   n=raw_input('#')
   if n==None:
      break
   numbers.append()

also it's best to use the raw_input function than to use the regular input function.

ov3rcl0ck 25 Junior Poster

I have looked more into pstgresql since my last post and want to refine my questions. From what I understand limiting who can connect to the database server is very easy with postgresql. You can use usernames and passwords along with allowing only certain ip addresses.

So as long as you are connected to the office intranet, know the name of the host of the database server, know a username and password and you have an allowed ip address, you should be able to get access to the server...no matter where you are? If the database server is hosted on either a computer or server on the private office intranet, do you need to be on the private office intranet to access it, or just simply connected to the internet somewhere?

could basically set it up either way, you can host it on your LAN or you can host it on the internet, if you host it on your LAN its only going to be available to your local network in your office, if you host it online then it can be accessed anywhere, but of course you can restrict access based on IP you could probably just use IPtables to filter IP's.

ov3rcl0ck 25 Junior Poster

Random generation IS very predictable, not to mention a brute force could probably crack that in about 5min. Cryptography is really intense, and your not really using an algo, more like a formula. Not too mention most encryption methods use randomly generated keys, and TrueCrypt for example uses your mouse movement to generate a random key(which is a good it). So your idea, its not gonna work, if you want to try it i can garuntee that if you give me the source code and something that you encrypted with it i can reverse engineer and crack the encryption in about 2 min.

ov3rcl0ck 25 Junior Poster

I prefer Postgre because I don't like many aspects of MySQL and its preformance. If needed you can use serialization+threading to acheive this, or make your own database using one of pythons many databasing libraries.

ov3rcl0ck 25 Junior Poster

Yeah you'll need to use exceptions, but if you want the script to continue after the error you're going to have to "pass" it, try this:

for i in range(1, 638):
    try:
        temp=start+str(i)
        permlist.append(str(url.urlopen(temp).readlines()[88]))        textlist.append(str(url.urlopen(temp).readlines()[77]))
    except Error, err:
        print "Index Error: %d at %d" % (err, i)
        pass

this will not only print the error and the location of the error but will also pass to keep the loop going.