Saturday, 21 November 2020

40. Pyhton Song

#This is to show you how to create several outputs with just one piece of code 

def lyrics0(stuff, num_repeats): #This command tells python that lyrics0 is two things:stuff and num_repeats


  return stuff*num_repeats #This means that when lyrics0 is called, it will print stuff multiplied by num_repeats


lyrics1 = lyrics0('Row ',3) + lyrics0('Your Boat. ', 1)+lyrics0('''

''', 1) #This is saying first to write three 'Row', one 'Your Boat' and one paragraph for spacing, because the script is a poem


lyrics2 = lyrics0('Gently down the stream  ', 1)+lyrics0('''

''', 1) #lyrics2, lyrics3 and lyrics4 do the same as lyrics1 but with different things to write


lyrics3 = lyrics0('Happily  ',4)+lyrics0('''

''', 1)


lyrics4 = lyrics0('Life is such a dream ', 1)


song = (lyrics1 + lyrics2 + lyrics3 + lyrics4+'''

        ''' + '''

''') #this command is saying to python: 'song is lyrics1, lyrics2, lyrics3, lyrics4 and two paragraphs all joined together


print(song*4) #As the last part, we are telling python to print song four times.

#Miguel Angel Trejo's song

Monday, 8 June 2020

51 . Bruteforce attack

#On Monday you created a password : this is the code:

print ('Hello, Its Monday')
print ('create a number-password')
NEWPASS = int(input())
print ('Thank you, bye')
print('')

#On Tuesday hackers entered the system.
#THE AUTOMATIC BRUTEFORCE STARTS HERE.
#Hackers cannot see the above code (The monday password)

import time
print ('Hello, Its Tuesday')

a=0
while NEWPASS != a:
  print ('To enter the system please introduce your password')
  a=a+1
  print (a)
   
print ('Welcome to MI6')

50 One-word encryption (permutation code) hacked (+ grammar attack)

#One-word encryption (permutation code) hacked (+ grammar attack)
#Think of the name of a common animal.
#Encrypt it: change its letters of order cat---> act


# HACKED
while True:
    print ('')
    print ('Paste the encrypted text here:')
    ET = str(input())

    import itertools

    l = itertools.permutations(str(ET))
    output= ([str(''.join(x)) for x in l])
    print (output)

    #for elem in ET:
     #   print ((elem, end = '') )                #  , end = ''
     
    #elem = elem.lower()

###########################################################
#DICC is the dictionary of
    while True: 
        DICC = ["cat", "bat", "rat", "elephant", "dog"]

        for x in DICC:
            if x in output:
                print (x)
            else:
                print ('...')
        break

     
 


 

 


49 #Caesar code Encrypt / Decrypt with password

#Caesar code Encrypt / Decrypt with password

#List of characters:
#import string
#print (string.printable)

L1 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[\]^_`{|}~' *999999 #This multiplies the extension of L1
           #L1 must contain all possible keyboard symbols
           #Randomeness in L1 increases layer of unpredictivity

while True:
    print ('')
    print ('')
    print ('Encript=E /Decrypt=D')
    EorD = input()
    EorD = EorD.lower()
    if EorD == 'e':
       
        #Message
        print('')
        print ('Introduce text to encrypt.')
        MESS = input()
       
        #Password (number of translations)
        print ('6-digit Numerical Password')
        PASS = int(input())
       
        #Item by item translation
        for LETTER in MESS:
            NEWPOS = L1.find(LETTER)+ PASS
            if NEWPOS == 0 :
                print ('fuc')
                break
            elif NEWPOS >= len(L1):
                print ('try again with a smaller password')
            print (L1[NEWPOS], end = '')
           
    elif EorD == 'd':
        #Message
        print('')
        print ('Paste text to decrypt.')
        MESS = input()
       
        #Password (number of translations)
        print ('6-digit Numerical Password')
        PASS = int(input())
       
        #Item by item translation
        for LETTER in MESS:
            NEWPOS = L1.find(LETTER)- PASS
            if NEWPOS < 0:
                print ( end = '')
           
            print (L1[NEWPOS], end = '')

     
       
 

48 Decryption: Caesar

#Caesar code DECRYPT -1

#L1 = ['a','e'] # + swap 'find' for 'index'
L1 = 'aeiou'
print (' introdu')
MESS = input ()

for LETTER in MESS:
    NEWPOS = L1.find(LETTER)-1 # Decrypt +1 ---> -1
    if NEWPOS == -2 :
        print ('\nthe letter ' + LETTER+ ' is not included')
        break
    elif NEWPOS <0:  # >= len (L1) -----> < 0
        NEWPOS = len(L1) -1 # 0 ----> len(L1) -1       
    print (L1[NEWPOS], end = '')

47 Encryption: Caesar

#Caesar code

#L1 = ['a','e'] # + swap 'find' for 'index'
L1 = 'aeiou'
print (' introdu')
MESS = input ()

for LETTER in MESS:
    NEWPOS = L1.find(LETTER)+1 #find the position in L1, +1
    if NEWPOS == 0 :
        print ('\nthe letter ' + LETTER+ ' is not included so i stop')
        break #quit() if you want to kill it
    elif NEWPOS >= len(L1):
        NEWPOS = 0    #solving last item +1 error
    #print (L1.find(LETTER))  #Finds the position of the item in a list
    print (L1[NEWPOS], end = '') #cancels the default print-newline

Tuesday, 2 June 2020

39. Upeercase / Lowercase

print ('Do you believe in God?')
a = input ( ) 
a = a.lower() #All goes lowercase. Try capitals and see

if a == ('yes'):
    print ('You are a believer')
elif a == ('no'):
    print ('You are either an agnostic or an atheist')
else:
    print ('No wanna talk with me? Bye!')

38. itertools.permutations(str(myInt))

import itertools
myInt = 123
l = itertools.permutations(str(myInt))
for x in l:
  print (x)

Monday, 20 April 2020

47 #Painting in python

#Making a MANDALA in python

print('choose a colour that will be the colour of the line drawn')
colourline=input()
print('choose a colour that will be the filling colour')
colourfill=input()
print('choose a number from 100 to 250 that will be the number of pixels the arro moves forwards creating a line')
a=int(input())
print('now choose a number from 90 to 360 that will be the degrees the arrow turns clockwise')
b=int(input())
print('write a number from 10 to 70 that will be the diameter of the circle that the arrow draws')
c=int(input())

from turtle import *
color(colourline,colourfill) #1st colour is the colour of the line and 2nd is the colour it feels the picture in when it's finished
begin_fill()
while True:
    forward(a) #number of pixels it moves forward
    right(b)#degrees it turns anti-clockwise(left) and clockwise(right)
    circle(c)#draws a circle of a diameter of the number you've said to him after moving the number of pixels you've told python

    if abs(pos()) < 1: #this will make it so that the arrow dosen't stop the fist time it reaches the place said
        print('Run again? (yes/no): ')
        answer=input()
        if answer == 'yes':
            continue #this will repeat the pattern created
        if answer == 'no':
            break #this will stop the program
end_fill() #this command will fill the final picture with the second colour chosen by the person who tries the program
done()