Python Learning: Implementing a String for encryption

Source: Internet
Author: User
Tags ord

"' Title description 1, the input string is added and decrypted, and output. 2 The encryption method is: When the content is the English letter is replaced with the letter, and the letter is changed case, such as the letter A is replaced by B, the letter z is replaced by A; When the content is a number add 1, such as 0 replaces the replacement of 2,9 replacement 0, the other characters do not change. S ' ' # -*- coding: utf-8 -*-import re# determine if the letter is Def isletter (letters):     if len (letter)  != 1:        return 0     else:        num_re =  ' [a-z]| [A-z] '         pattern = re.compile (num_re)          result = re.match (Pattern, letter)          if result == None:             return 0        else:             return 1# determines if the letter is lowercase: def islower (Letters):    &nbsP;if letter.lower () ==letter:        return 1     else:        return 0# determine if the letter is Z/zdef isz (Letters):     if letter.lower () = = ' Z ':         return  1    else:        return 0# Encryption def for English letters  encryletter (letter):     if isz (letter) = = ' Z ':         if islower (letter) ==1:             return  ' A '         else:             return  ' A '     else:         if islower (letter) ==1:             return chr(Ord (letter) +1-32)         else:             RETURN CHR (ord (letter)) +1+32) #对数字进行加密def  encrynum (num):     if num==9:        return 0     else :        return int (num) +1#  Determine if it is a number: Def isnum (VAR):     if len (Var)  != 1:         return 0    else:         num_re =  ' [0-9] '         pattern = re.compile (num_re)         result = re.match (Pattern, var)          if result == None:             return 0        else:             return 1# encrypts a character def encrypt_single (character):     if isletter (character) ==1:        return encryletter ( character)     if isnum (character) ==1:         Return encrynum (character)     else:         The Return character "interface describes the:     implementation interface, each interface implements 1 basic operations:void encrypt  (char  Aucpassword[], char aucresult[]): Implement string encryption in this function and output description: 1, the string ends with a. 2, string maximum 100 characters. "' Def encrypt ():    while 1:         Unencrypt = input (' Enter the string to be encrypted, and the string length is not greater than 8: ')         if  Len (unencrypt) >8:             print ("String length greater than 8, please re-enter!") \ n ")             continue         else:            break     encrypt_str=[]    for i in range (Len (unEncrypt)):         encrypt_str.append (Encrypt_single (unEncrypt[i))      print (ENCRYPT_STR) Encrypt ()


Python Learning: Implementing a String for encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.