Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- # 1. Create a list with all the primes
- primes = [2] # Firstly, my list primes contains only the number 2
- counter = 0
- for i in range(3, 1000):
- flag = True # Initially, I suppose that flag = true ---> my number is prime
- for j in range(2, math.floor(i/2)):
- if i % j == 0:
- flag = False # If I find a "j": i % j == 0 ---> i can be divided with j ---> i NOT PRIME
- break
- if flag == True: # That means that j-loop didn't go in if-statement for NOT PRIMES
- primes.append(i)
- # GIA KAPOIO LOGO MOU VAZEI KAI TO '4' SAN PRIME OPOTE TON KANW REMOVE
- primes.remove(4)
- # Display the primes from 1 to 1000
- #print(primes)
- #print()
- # 2. Create a list named alphabet containing all the letters in the correct row
- word = "abcdefghijklmnopqrstuvwxyz"
- alphabet = []
- for ch in word:
- alphabet.append(ch)
- #print(alphabet)
- #print()
- # 3. Ask the user to give me the appropriate numbers
- print("*******************************************************************************************")
- print("*******************************************************************************************")
- length = int(input("Enter how many numbers you will give me (this length + 1 will be the length of the word:): "))
- numbers = [] # I will fill the list with numbers given by the user (list.size will be length)
- for i in range(length):
- userNumber = int(input("Give me the number " + str(i+1) + ": "))
- numbers.append(userNumber)
- print()
- print(" Your numbers : " + str(numbers))
- # 4. Spaw to 1o ginomeno, gia na exw to 1o psifio kai meta kanw "length" epanalipseis
- diairetis1 = 1
- for i in range(len(primes)):
- if numbers[0] % primes[i] == 0:
- diairetis1 = primes[i]
- break
- diairetis2 = numbers[0] / diairetis1
- diairetis3 = 1
- for i in range(len(primes)):
- if numbers[1] % primes[i] == 0:
- diairetis3 = primes[i]
- break
- diairetis4 = numbers[1] / diairetis3
- # Arxizw na ftiaxnw tin lista me ta noumera-apantiseis
- wordNumbers = []
- arxi = 0
- '''
- if diairetis1 == diairetis3:
- arxi = diairetis2
- if diairetis1 == diairetis4:
- arxi = diairetis2
- if diairetis2 == diairetis3:
- arxi = diairetis1
- if diairetis2 == diairetis4:
- arxi = diairetis1
- wordNumbers.append(arxi)
- print(arxi)
- '''
- for check in range(length-1):
- diairetis1 = 1
- for i in range(len(primes)):
- if numbers[check] % primes[i] == 0:
- diairetis1 = primes[i]
- break
- diairetis2 = numbers[check] / diairetis1
- diairetis3 = 1
- for i in range(len(primes)):
- if numbers[check+1] % primes[i] == 0:
- diairetis3 = primes[i]
- break
- diairetis4 = numbers[check+1] / diairetis3
- synexeia = 0
- if diairetis1 == diairetis3:
- synexeia = diairetis2
- if diairetis1 == diairetis4:
- synexeia = diairetis2
- if diairetis2 == diairetis3:
- synexeia = diairetis1
- if diairetis2 == diairetis4:
- synexeia = diairetis1
- wordNumbers.append(synexeia)
- # An eftasa sto telos
- if check == length - 2:
- if diairetis1 == diairetis3:
- synexeia = diairetis1
- if diairetis1 == diairetis4:
- synexeia = diairetis1
- if diairetis2 == diairetis3:
- synexeia = diairetis2
- if diairetis2 == diairetis4:
- synexeia = diairetis2
- wordNumbers.append(synexeia)
- # Gia to TELEYTAIO NOUMERO, giati tha prepei na mpoun "length + 1" noumera
- # Tha tsekarw ton teleytaio arithmo tou numbers list: Tha ton sygkrinw me to teleytaio noumero ths listas wordNumbers
- diairetisLast1 = 0
- diairetisLast2 = 0
- for i in range(len(primes)):
- if numbers[length-1] % primes[i] == 0: # An to last number tou numbers % me kapoion prime == 0
- diairetisLast1 = primes[i]
- diairetisLast2 = numbers[length-1] / diairetisLast1
- break
- # Exw vrei tous 2 diairetes tou numbers[length-1]
- # Tha tsekarw poios apo tous 2 einai o last tis listas wordNumbers
- if diairetisLast1 == wordNumbers[len(wordNumbers)-1]:
- wordNumbers.append(diairetisLast2)
- else:
- wordNumbers.append(diairetisLast1)
- print(" The products : " + str(wordNumbers))
- # Create a list named "message", in which I append the letter coming from "alphabet" list, which is positioned in index
- message =[]
- for i in range(len(wordNumbers)):
- message.append(alphabet[int(wordNumbers[i] - 1) % len(alphabet)])
- print("Encrypted message: " + ''.join(map(str, message)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement