Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. #!/usr/bin/python
  2. #-*- coding:utf-8 -*-
  3.  
  4. import sys
  5. def proba(str):
  6.     tmp=""
  7.     str=str.upper()
  8.     for c in str:
  9.         if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
  10.             tmp+=c
  11.     list=strToList(tmp)
  12.     print list
  13.     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 ]
  14.     for i in range(0, len(tmp)):
  15.         print (list.count(list[i])/len(tmp))*100;
  16.         listProba[(ord(list[i])-ord('A'))]=(list.count(list[i])/len(tmp))*100;
  17.     print listProba
  18.    
  19.    
  20.  
  21. def strToList(str):
  22.     list = []
  23.     for c in str :
  24.         list.append(c)
  25.     return list
  26.        
  27. def cryptage(strStart, key):
  28.     i = 0
  29.     res=""
  30.     key=key.upper()
  31.     nbKey=len(key)
  32.     strStart=strStart.upper()
  33.     key=strToList(key)
  34.     for c in strStart :
  35.         if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
  36.             tmpMot=ord(c)-ord('A')
  37.             tmpCle = ord(key[i%nbKey])-ord('A')
  38.             print chr((tmpMot + tmpCle)%26 + ord('A'))
  39.             i = i + 1
  40.         else :
  41.             print c
  42.        
  43.  
  44. def decryptage(strStart, key):
  45.     i = 0
  46.     res=""
  47.     key=key.upper()
  48.     nbKey=len(key)
  49.     strStart=strStart.upper()
  50.     key=strToList(key)
  51.     for c in strStart :
  52.         if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
  53.             tmpMot=ord(c)-ord('A')
  54.             tmpCle = ord(key[i%nbKey])-ord('A')
  55.             tmp = chr((tmpMot - tmpCle)%26 + ord('A'))
  56.             if (( ord(tmp)<ord('A') )) :
  57.                 tmp=chr(ord(tmp)+26)
  58.             print tmp
  59.             i = i + 1
  60.         else :
  61.             print c
  62.  
  63.        
  64. def hack(strStart):
  65.     tmp = ""
  66.     strStart=strStart.upper()
  67.     for c in strStart:
  68.         if (( ord(c)>=ord('A') and ord(c)<=ord('Z'))):
  69.             tmp+=c
  70.     tmp=strToList(tmp)
  71.     proba(strStart)
  72.        
  73.    
  74.    
  75.  
  76.  
  77. def main():
  78.     choix=int(-1)
  79.  
  80.     print"\n   1 - Cryptage \n\n   2 - Décryptage\n\n   3 - Décryptage forcé\n\n   0 - Quitter\n\n";
  81.     while (( choix!=1 and choix!=2 and choix!=3 and choix!=0 )):
  82.         choix=int(raw_input("Votre choix : "))
  83.     if choix==0 :
  84.         sys.exit()
  85.     strStart = raw_input("Entrez la chaine à  analyser : ")
  86.     if choix!=3 :
  87.         key=raw_input("Entrez votre clé de cryptage : ")
  88.     if choix==1 :
  89.         cryptage(strStart, key)
  90.     if choix==2 :
  91.         decryptage(strStart, key)
  92.     if choix==3 :
  93.         hack(strStart)
  94.    
  95.    
  96. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement