Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #-*- coding:utf-8 -*-
- import sys
- def proba(str):
- tmp=""
- str=str.upper()
- for c in str:
- if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
- tmp+=c
- list=strToList(tmp)
- print list
- listProba = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- for i in range(0, len(tmp)):
- print (list.count(list[i])/len(tmp))*100;
- listProba[(ord(list[i])-ord('A'))]=(list.count(list[i])/len(tmp))*100;
- print listProba
- def strToList(str):
- list = []
- for c in str :
- list.append(c)
- return list
- def cryptage(strStart, key):
- i = 0
- res=""
- key=key.upper()
- nbKey=len(key)
- strStart=strStart.upper()
- key=strToList(key)
- for c in strStart :
- if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
- tmpMot=ord(c)-ord('A')
- tmpCle = ord(key[i%nbKey])-ord('A')
- print chr((tmpMot + tmpCle)%26 + ord('A'))
- i = i + 1
- else :
- print c
- def decryptage(strStart, key):
- i = 0
- res=""
- key=key.upper()
- nbKey=len(key)
- strStart=strStart.upper()
- key=strToList(key)
- for c in strStart :
- if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
- tmpMot=ord(c)-ord('A')
- tmpCle = ord(key[i%nbKey])-ord('A')
- tmp = chr((tmpMot - tmpCle)%26 + ord('A'))
- if (( ord(tmp)<ord('A') )) :
- tmp=chr(ord(tmp)+26)
- print tmp
- i = i + 1
- else :
- print c
- def hack(strStart):
- tmp = ""
- strStart=strStart.upper()
- for c in strStart:
- if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
- tmp+=c
- tmp=strToList(tmp)
- proba(strStart)
- def main():
- choix=int(-1)
- print"\n 1 - Cryptage \n\n 2 - Décryptage\n\n 3 - Décryptage forcé\n\n 0 - Quitter\n\n";
- while (( choix!=1 and choix!=2 and choix!=3 and choix!=0 )):
- choix=int(raw_input("Votre choix : "))
- if choix==0 :
- sys.exit()
- strStart = raw_input("Entrez la chaine à analyser : ")
- if choix!=3 :
- key=raw_input("Entrez votre clé de cryptage : ")
- if choix==1 :
- cryptage(strStart, key)
- if choix==2 :
- decryptage(strStart, key)
- if choix==3 :
- hack(strStart)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement