Friday, November 14, 2014

Python use dll

Use dll in Python

from ctypes import*
mydll = cdll.LoadLibrary("my_library.dll")
result1= mydll.addition(8,20)
result2= mydll.subtraction(9,8)
print(result1,result2)


Author:MarcinLanguage:Python 3.4Info: How to use dll functions in your python script. This is also possible with the    windows api dll's ,)

Thursday, November 13, 2014

Factorial in Python

Factorial in Python

def Factorial(zahl):
    result=1
    for i in range(zahl):
        result=result*(zahl-i)
    return result


Author:Marcin
Language:Python 3.4
Info: The math function factorial ! in python. The only limitation you have is your hardware ,)

Power To math in Python

Power to in Python

def power(number,to):
    'potenz'
    result=number
    for i in range(int(to)-1):
        result=result*number
    return result


Author:Marcin
Language:Python 3.4
Info: The implementation of the power to math function in python. Its not limited, only by your ramspace ,)

Square root in python

Square root in python

from math import *

def square_root(number,wie_genau):
    'Heron'
    if number>0:
        x_one=decimal.Decimal(number);y_one=decimal.Decimal(1)
        for i in range(int(wie_genau)):
            x_two=decimal.Decimal(((x_one+y_one)/2))
            y_two=decimal.Decimal((number/x_one))
            #
            x_one=x_two
            y_one=y_two
        return decimal.Decimal(x_one)
    else:
        print("No Negative Numbers!")


Author:Marcin Cherek
Language:Python 3.4
Info: A little Implementation of the math function square root in python. I am using the Heron Algorithm.

Wednesday, November 12, 2014

Simple cipher in Python

Cipher in Python



#usr/bin/python
import os
import sys

__version__="1.0"
__author__="Marcin"
#**********************
Letters="abcdefghijklmnopqrstuvwxyz 1234567890-+*/_:;()[]{}\n'="
Letters+='",üäö$!?.<>'
Letter_dict={}
Letter_dict_2={}
u=0
for i in Letters:
    u=u+1
    Letter_dict.update({i:u})
    Letter_dict_2.update({u:i})
#print(Letter_dict)
#print("********")
#print(Letter_dict_2)
#*********************
class cipher_caesar:
    def __init__(self,key,old_t,file_=None):
        self.key=key
        self.new_t=""
        self.old_t=old_t
        if(file_ !=None):
            self.file_=file_

    def code(self,text=None):
        if text!=None:
            self.old_t=text
        if self.key!=0:
            count=1
            for i in self.old_t:
                if(int(Letter_dict[i.lower()]+self.key)1 or Letter_dict[i.lower()]-self.key==1):
                    self.new_t+=Letter_dict_2[int(Letter_dict[i.lower()]-self.key)]
                else:
                    self.new_t+=Letter_dict_2[len(Letters)-int(self.key-Letter_dict[i.lower()])]
                count+=1
        else:
            print("Ungültiger key")
        return self.new_t

def MAIN(args):
    print("")
    if(len(args)==1):
        weiter=True
        while(weiter):
            if(input("crypt:1/decrypt:2 : ")=="1"):
                text=str(input("Text:"))
                key=int(input("Key:"))
                c=cipher_caesar(key,text)
                crypted=c.code(None)
                print("crypted:",crypted)
            else:
                text=input("Text:")
                key=int(input("Key:"))
                c=cipher_caesar(key,text)
                crypted=c.decode(None)
                print("->",crypted)
                input()
                return crypted
        else:
            exit()
    else:
        file_=None
        key=""
        modus=0
        text=""
        for i in range(len(args)):
            if args[i]=="-key":
                key=int(args[i+1])
            elif args[i]=="-code":
                modus=1
            elif args[i]=="-decode":
                modus=2
            elif args[i]=="-text":
                text=str(args[i+1])
            elif args[i]=="-file":
                file_=str(args[i+1])
            else:None
        if(file_==None):
            c=cipher_caesar(key,text)
            if(modus==1):v=c.code(None)
            else:v=c.decode(None)
        else:
            if(os.path.exists(file_)):
                c=cipher_caesar(key,text,file_=file_)
                if(modus==1):v=c.code_file()
                else:v=c.decode_file()
            else:
                print("FILE DOES NO EXIST")
            
MAIN(sys.argv)

Author:Marcin

Language:Python 3.4
Description: A implementation of one of the simplest algorithms for ciphers, the caesar cipher. You can run it also in the console with args.You can crypt and decrypt files.

Saturday, November 8, 2014

Read Prozess Memory

Read Protess Memory in Python


import ctypes
from ctypes import *
from ctypes.wintypes import *
#import win32api
import psutil
import sys

numeprocess= "chrome.exe"
adresahexmem = 0x01012964
nrbcititi = 147

def getpid():
  for proc in psutil.process_iter():
    print(proc.name)
    if str(numeprocess) in str(proc.name):
      print(proc.pid)
      return proc.pid

PROCESS_VM_READ = 0x0010

if getpid() == None:
  print("numr:",numeprocess)
  sys.exit()
else:
  PID = getpid()

process = windll.kernel32.OpenProcess(PROCESS_VM_READ,0,PID)
readprocmem = windll.kernel32.ReadProcessMemory
bufferbcititi = ctypes.create_string_buffer(nrbcititi)

for i in range(1,1000):
  try:
    if readprocmem(process,hex(i),bufferbcititi,nrbcititi,0):
      print(bufferbcititi.raw)
  except:None

Sunday, November 2, 2014

Image parser in Python

Image Parser



import urllib.request

def parse_links(source):
    links=[]
    t=str(source).split('<img src=&quot')
    for i in t:
        r=str(i).split('&quot')
        links.append(r[0])
    return links
        

def download(links):
    name=0
    for i in links:
        try:
            v=urllib.request.urlopen(i)
            f=open(str(name)+&quot.jpg&quot,&quotwb&quot)
            f.write(v.read())
            f.close()
            name+=1
        except:print(&quotC&quot)

def load_source(website):
    s=urllib.request.urlopen(website)
    v=s.read()
    return v
    
def main():
    search=input(&quotStart:&quot)
    source=load_source(&quothttp://nzz.ch&quot)
    links=parse_links(source)
    download(links)
    for i in links:print(i)
    print(&quotEND&quot)
    
main()

Author: Marcin
Language: Python 3.4
Infos: 
A simple Script for filtering out Images of a website or just a html file. It's a simple parser that searches
for tags with Images in it and downloads these.
Video: https://www.youtube.com/watch?v=_-Lecym-BP0&feature=youtu.be

link parser in Python

Link Parser


import urllib.request

def parse_links(source):
    links=[]
    t=str(source).split('<a href="')
    for i in t:
        r=str(i).split('"')
        links.append(r[0])
    return links
        
    
def load_source(website):
    s=urllib.request.urlopen(website)
    v=s.read()
    return v
    
def main():
    search=input("Start:")
    source=load_source("http://nzz.ch")
    links=parse_links(source)
    for i in links:print(i)
    print("END")
    
main()


Author:Marcin
Language:Python 3.4
Infos: 
A simple Script for filtering out links of a website or just a html file. It's a simple parser that searches
for tags with links in it and save these.
Video: https://www.youtube.com/watch?v=mbFovXwFWn4

Fibonacci in python

Fibonacci Python


import os
import sys

def fib(a,b,count):
    c=a+b
    a=c
    b=c+b
    print(a)
    print(b)
    if count<100: a="" b="" count="" else:="" fib="" nde="" pre="" print="">


Author:Marcin
Language:Python 3.4
Infos: 
fibonacci Numbers with recursiv programming in python. Shows the next 100 numbers of fib function. But you can show more. Just manipulate the count in the fib function.
Video: https://www.youtube.com/watch?v=MrhpbPXxZbY

Bubble sort in python

Bubble sort


import os
import sys

def bubble_sort(Array):
    for i in range(0,len(Array)):
        for t in range(0,len(Array)):
            if int(Array[i])
Author: Marcin
Language:Python 3.4
Infos:
EN:This is a little snippet in python, that implements Bubble sort in the simplest form.
DE:Ein kleines script in python ,welches bubble sort sehr einfach implementiert.
Video: https://www.youtube.com/watch?v=qzQUjMDAwT0