加密软件
谷歌搜registration codes python和license keys pythonhttps://build-system.fman.io/generating-license-keys
https://codereview.stackexchange.com/questions/95499/register-login-and-authentication-through-terminal
获取MAC地址并生成序列号,从序列号生成激活密钥
# 不足十位左边加零
while True:
num = input('Enter a number : ')
print('The zero-padded number is : ', str(num).rjust(10, '0'))
查找n个自然数的和
查找可被另一个数字整除的数字
将十进制转换为二进制,八进制和十六进制
带有前缀的数字0b 被认为是二进制,0o 被认为是八进制和0x 十六进制
ord()函数将字符转换为整数(ASCII值)
chr()函数从相应的ASCII值中获取字符
打印斐波那契序列
斐波那契数列是0、1、1、2、3、5、8 ...的整数序列。
前两项为0和1。所有其他项均通过将前两项相加而获得。这意味着第n个项是第(n-1)个和第(n-2)个项的和
检查阿姆斯特朗号(3位数字)
153 = 1 * 1 * 1 + 5 * 5 * 5 + 3 * 3 * 3 // 153是阿姆斯特朗数
检查阿姆斯壮的n位数字
两个整数之间的所有Armstrong数字
分别使用字典、使用列表和字典理解来计算字符串中每个元音的数量
数字的阶乘是从1到该数字的所有整数的乘积。
例如,阶乘6是1*2*3*4*5*6 = 720。没有为负数定义的阶乘,零阶的阶乘是1、0!= 1
使用递归将十进制转换为二进制
使用递归计算给定数字的总和
使用递归显示斐波那契数列
制作一个简单的计算器
随机播放一副纸牌
显示给定日期的日历
查找两个数字的最小公倍数(LCM:The least common multiple )
两个数的乘积等于这两个数的最小公倍数和最大公除数的乘积
Number1 * Number2 = L.C.M. * G.C.D.
使用欧几里得算法计算两个数字的最大公除数(GCD:greatest common divisor)
查找HCF或GCD
- # Sum of natural numbers up to num
- num = 16
- if num < 0:
- print("Enter a positive number")
- else:
- sum = 0
- # use while loop to iterate until zero
- while(num > 0):
- sum += num
- num -= 1
- print("The sum is", sum)
- # Display the powers of 2 using anonymous function
- terms = 10
- # Uncomment code below to take input from the user
- # terms = int(input("How many terms? "))
- # use anonymous function
- result = list(map(lambda x: 2 ** x, range(terms)))
- print("The total terms are:",terms)
- for i in range(terms):
- print("2 raised to power",i,"is",result[i])
- # Take a list of numbers
- my_list = [12, 65, 54, 39, 102, 339, 221,]
- # use anonymous function to filter
- result = list(filter(lambda x: (x % 13 == 0), my_list))
- # display the result
- print("Numbers divisible by 13 are",result)
带有前缀的数字0b 被认为是二进制,0o 被认为是八进制和0x 十六进制
- # Python program to convert decimal into other number systems
- dec = 344
- print("The decimal value of", dec, "is:")
- print(bin(dec), "in binary.")
- print(oct(dec), "in octal.")
- print(hex(dec), "in hexadecimal.")
chr()函数从相应的ASCII值中获取字符
- # Program to find the ASCII value of the given character
- c = 'p'
- print("The ASCII value of '" + c + "' is", ord(c))
- >>> chr(65)
- 'A'
- >>> chr(120)
- 'x'
- >>> chr(ord('S') + 1)
- 'T'
质数,又称素数,指在大于1的自然数中,除了1和该数自身外,无法被其他自然数整除的数
- # Program to check if a number is prime or not
- num = 407
- # To take input from the user
- #num = int(input("Enter a number: "))
- # prime numbers are greater than 1
- if num > 1:
- # check for factors
- for i in range(2,num):
- if (num % i) == 0:
- print(num,"is not a prime number")
- print(i,"times",num//i,"is",num)
- break
- else:
- print(num,"is a prime number")
- # if input number is less than
- # or equal to 1, it is not prime
- else:
- print(num,"is not a prime number")
- # Python program to display all the prime numbers within an interval
- lower = 900
- upper = 1000
- print("Prime numbers between", lower, "and", upper, "are:")
- for num in range(lower, upper + 1):
- # all prime numbers are greater than 1
- if num > 1:
- for i in range(2, num):
- if (num % i) == 0:
- break
- else:
- print(num)
四年一闰、百年不闰,四百年再闰
- # Python program to check if year is a leap year or not
- year = 2000
- # To get year (integer input) from the user
- # year = int(input("Enter a year: "))
- if (year % 4) == 0:
- if (year % 100) == 0:
- if (year % 400) == 0:
- print("{0} is a leap year".format(year))
- else:
- print("{0} is not a leap year".format(year))
- else:
- print("{0} is a leap year".format(year))
- else:
- print("{0} is not a leap year".format(year))
try: print('Please enter year to check for leap year') year = int(input()) except ValueError: print('Please input a valid year') exit(1) if year % 400 == 0: print('Leap Year') elif year % 100 == 0: print('Not Leap Year') elif year % 4 == 0: print('Leap Year') else: print('Not Leap Year')
打印斐波那契序列
斐波那契数列是0、1、1、2、3、5、8 ...的整数序列。
前两项为0和1。所有其他项均通过将前两项相加而获得。这意味着第n个项是第(n-1)个和第(n-2)个项的和
- # Program to display the Fibonacci sequence up to n-th term
- nterms = int(input("How many terms? "))
- # first two terms
- n1, n2 = 0, 1
- count = 0
- # check if the number of terms is valid
- if nterms <= 0:
- print("Please enter a positive integer")
- elif nterms == 1:
- print("Fibonacci sequence upto",nterms,":")
- print(n1)
- else:
- print("Fibonacci sequence:")
- while count < nterms:
- print(n1)
- nth = n1 + n2
- # update values
- n1 = n2
- n2 = nth
- count += 1
检查阿姆斯特朗号(3位数字)
153 = 1 * 1 * 1 + 5 * 5 * 5 + 3 * 3 * 3 // 153是阿姆斯特朗数
- # Python program to check if the number is an Armstrong number or not
- # take input from the user
- num = int(input("Enter a number: "))
- # initialize sum
- sum = 0
- # find the sum of the cube of each digit
- temp = num
- while temp > 0:
- digit = temp % 10
- sum += digit ** 3
- temp //= 10
- # display the result
- if num == sum:
- print(num,"is an Armstrong number")
- else:
- print(num,"is not an Armstrong number")
检查阿姆斯壮的n位数字
- num = 1634
- # Changed num variable to string,
- # and calculated the length (number of digits)
- order = len(str(num))
- # initialize sum
- sum = 0
- # find the sum of the cube of each digit
- temp = num
- while temp > 0:
- digit = temp % 10
- sum += digit ** order
- temp //= 10
- # display the result
- if num == sum:
- print(num,"is an Armstrong number")
- else:
- print(num,"is not an Armstrong number")
两个整数之间的所有Armstrong数字
- # Program to check Armstrong numbers in a certain interval
- lower = 100
- upper = 2000
- for num in range(lower, upper + 1):
- # order of number
- order = len(str(num))
- # initialize sum
- sum = 0
- temp = num
- while temp > 0:
- digit = temp % 10
- sum += digit ** order
- temp //= 10
- if num == sum:
- print(num)
生成一个十个字符的字母数字密码,至少包含一个小写字符,至少一个大写字符和至少三位数字
https://docs.python.org/3/library/secrets.html
- import string
- import secrets
- alphabet = string.ascii_letters + string.digits
- while True:
- password = ''.join(secrets.choice(alphabet) for i in range(10))
- if (any(c.islower() for c in password)
- and any(c.isupper() for c in password)
- and sum(c.isdigit() for c in password) >= 3):
- break
- print(password)
- # Program to count the number of each vowels
- # string of vowels
- vowels = 'aeiou'
- ip_str = 'Hello, have you tried our tutorial section yet?'
- # make it suitable for caseless comparisions
- # 方法casefold()返回字符串的小写版本
- ip_str = ip_str.casefold()
- # make a dictionary with each vowel a key and value 0
- count = {}.fromkeys(vowels,0)
- # count the vowels
- for char in ip_str:
- if char in count:
- count[char] += 1
- print(count)
- ---------------------------------------------------------------------
- # Using dictionary and list comprehension
- ip_str = 'Hello, have you tried our tutorial section yet?'
- # make it suitable for caseless comparisions
- ip_str = ip_str.casefold()
- # count the vowels
- count = {x:sum([1 for char in ip_str if char == x]) for x in 'aeiou'}
- print(count)
- # Program to sort alphabetically the words form a string provided by the user
- my_str = "Hello this Is an Example With cased letters"
- # To take input from the user
- #my_str = input("Enter a string: ")
- # breakdown the string into a list of words
- words = [word.lower() for word in my_str.split()]
- # sort the list
- words.sort()
- # display the sorted words
- print("The sorted words are:")
- for word in words:
- print(word)
- # define punctuation
- punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
- my_str = "Hello!!!, he said ---and went."
- # To take input from the user
- # my_str = input("Enter a string: ")
- # remove punctuation from the string
- no_punct = ""
- for char in my_str:
- if char not in punctuations:
- no_punct = no_punct + char
- # display the unpunctuated string
- print(no_punct)
- # Program to check if a string is palindrome or not
- my_str = 'aIbohPhoBiA'
- # make it suitable for caseless comparison
- my_str = my_str.casefold()
- # reverse the string
- rev_str = reversed(my_str)
- # check if the string is equal to its reverse
- if list(my_str) == list(rev_str):
- print("The string is a palindrome.")
- else:
- print("The string is not a palindrome.")
- # Python program to find the factorial of a number provided by the user.
- # change the value for a different result
- num = 7
- # To take input from the user
- #num = int(input("Enter a number: "))
- factorial = 1
- # check if the number is negative, positive or zero
- if num < 0:
- print("Sorry, factorial does not exist for negative numbers")
- elif num == 0:
- print("The factorial of 0 is 1")
- else:
- for i in range(1,num + 1):
- factorial = factorial*i
- print("The factorial of",num,"is",factorial)
数字的阶乘是从1到该数字的所有整数的乘积。
例如,阶乘6是1*2*3*4*5*6 = 720。没有为负数定义的阶乘,零阶的阶乘是1、0!= 1
- # Factorial of a number using recursion
- def recur_factorial(n):
- if n == 1:
- return n
- else:
- return n*recur_factorial(n-1)
- num = 7
- # check if the number is negative
- if num < 0:
- print("Sorry, factorial does not exist for negative numbers")
- elif num == 0:
- print("The factorial of 0 is 1")
- else:
- print("The factorial of", num, "is", recur_factorial(num))
- # Function to print binary number using recursion
- def convertToBinary(n):
- if n > 1:
- convertToBinary(n//2)
- print(n % 2,end = '')
- # decimal number
- dec = 34
- convertToBinary(dec)
- print()
使用递归计算给定数字的总和
- # Python program to find the sum of natural using recursive function
- def recur_sum(n):
- if n <= 1:
- return n
- else:
- return n + recur_sum(n-1)
- # change this value for a different result
- num = 16
- if num < 0:
- print("Enter a positive number")
- else:
- print("The sum is",recur_sum(num))
斐波那契数列是0、1、1、2、3、5、8 ...的整数序列。
前两个项是0和1。所有其他项是通过将前两个项相加而获得的。这意味着第n个项是第(n-1)个和第(n-2)个项的和
前两个项是0和1。所有其他项是通过将前两个项相加而获得的。这意味着第n个项是第(n-1)个和第(n-2)个项的和
- # Python program to display the Fibonacci sequence
- def recur_fibo(n):
- if n <= 1:
- return n
- else:
- return(recur_fibo(n-1) + recur_fibo(n-2))
- nterms = 10
- # check if the number of terms is valid
- if nterms <= 0:
- print("Plese enter a positive integer")
- else:
- print("Fibonacci sequence:")
- for i in range(nterms):
- print(recur_fibo(i))
制作一个简单的计算器
- # Program make a simple calculator
- # This function adds two numbers
- def add(x, y):
- return x + y
- # This function subtracts two numbers
- def subtract(x, y):
- return x - y
- # This function multiplies two numbers
- def multiply(x, y):
- return x * y
- # This function divides two numbers
- def divide(x, y):
- return x / y
- print("Select operation.")
- print("1.Add")
- print("2.Subtract")
- print("3.Multiply")
- print("4.Divide")
- while True:
- # Take input from the user
- choice = input("Enter choice(1/2/3/4): ")
- # Check if choice is one of the four options
- if choice in ('1', '2', '3', '4'):
- num1 = float(input("Enter first number: "))
- num2 = float(input("Enter second number: "))
- if choice == '1':
- print(num1, "+", num2, "=", add(num1, num2))
- elif choice == '2':
- print(num1, "-", num2, "=", subtract(num1, num2))
- elif choice == '3':
- print(num1, "*", num2, "=", multiply(num1, num2))
- elif choice == '4':
- print(num1, "/", num2, "=", divide(num1, num2))
- break
- else:
- print("Invalid Input")
随机播放一副纸牌
- # Python program to shuffle a deck of card
- # importing modules
- import itertools, random
- # make a deck of cards
- deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club']))
- # shuffle the cards
- random.shuffle(deck)
- # draw five cards
- print("You got:")
- for i in range(5):
- print(deck[i][0], "of", deck[i][1])
- # Program to display calendar of the given month and year
- # importing calendar module
- import calendar
- yy = 2014 # year
- mm = 11 # month
- # To take month and year input from the user
- # yy = int(input("Enter year: "))
- # mm = int(input("Enter month: "))
- # display the calendar
- print(calendar.month(yy, mm))
- # Python Program to find the L.C.M. of two input number
- def compute_lcm(x, y):
- # choose the greater number
- if x > y:
- greater = x
- else:
- greater = y
- while(True):
- if((greater % x == 0) and (greater % y == 0)):
- lcm = greater
- break
- greater += 1
- return lcm
- num1 = 54
- num2 = 24
- print("The L.C.M. is", compute_lcm(num1, num2))
两个数的乘积等于这两个数的最小公倍数和最大公除数的乘积
Number1 * Number2 = L.C.M. * G.C.D.
使用欧几里得算法计算两个数字的最大公除数(GCD:greatest common divisor)
- # Python program to find the L.C.M. of two input number
- # This function computes GCD
- def compute_gcd(x, y):
- while(y):
- x, y = y, x % y
- return x
- # This function computes LCM
- def compute_lcm(x, y):
- lcm = (x*y)//compute_gcd(x,y)
- return lcm
- num1 = 54
- num2 = 24
- print("The L.C.M. is", compute_lcm(num1, num2))
两个数字的最高公共因子(HCF)或最大公共除数(GCD)是将两个给定数字完美除的最大正整数
用于查找文件哈希的Python程序
- # Python program to find H.C.F of two numbers
- # define a function
- def compute_hcf(x, y):
- # choose the smaller number
- if x > y:
- smaller = y
- else:
- smaller = x
- for i in range(1, smaller+1):
- if((x % i == 0) and (y % i == 0)):
- hcf = i
- return hcf
- num1 = 54
- num2 = 24
- print("The H.C.F. is", compute_hcf(num1, num2))
- # 使用欧几里得算法
- # Function to find HCF the Using Euclidian algorithm
- def compute_hcf(x, y):
- while(y):
- x, y = y, x % y
- return x
- hcf = compute_hcf(300, 400)
- print("The HCF is", hcf)
- # Python rogram to find the SHA-1 message digest of a file
- # importing the hashlib module
- import hashlib
- def hash_file(filename):
- """"This function returns the SHA-1 hash
- of the file passed into it"""
- # make a hash object
- h = hashlib.sha1()
- # open file for reading in binary mode
- with open(filename,'rb') as file:
- # loop till the end of the file
- chunk = 0
- while chunk != b'':
- # read only 1024 bytes at a time
- chunk = file.read(1024)
- h.update(chunk)
- # return the hex representation of digest
- return h.hexdigest()
- message = hash_file("track1.mp3")
- print(message)
Python 之 生成数字签名
- import base64
- from Crypto.Hash import SHA256
- from Crypto.PublicKey import RSA
- from Crypto.Signature import PKCS1_v1_5
- private_key = b"""-----BEGIN RSA PRIVATE KEY-----
- MIICXgIBAAKBgQDjzE4mbSVTGxstkMT4zREzNX0wZCLzzNW4vDA9QH0pFMBGrgLF
- KPAmcTXa7wYLybUOKuQ/og9JCId9AgQuKFTyh67654nhugOPf0m8kcvRr77mAP56
- Po6fyrr8GWZBpbQ7hc+1EMNPc/E1REe3EMEzFaDFaQgCMwcwUTMiGGZ20QIDAQAB
- AoGAaij2arYG5PoG6m9DPGflEiZlVz3zhAb7uwIIwSLisVh4WvgRVmzDrkaoQIWQ
- HcI83INkp7sQwIp3Cez8ob4uB4/ZWdYvpSFY3dco7/iq+kQgycOwz34DVmUWddlc
- bXwoRanw/aH48AycQHO3QuBQeMkfeW33TbmpbzeDnF1unYECQQDzQmaxA28bn8Ec
- DnD/WbFOxIw/aIRKB4jEVgDfKOhGveTTtXor5UsxnRQYlFaONon9/coP/Ca4y27a
- Acl7Bw4ZAkEA77qZro7vme5D5tIo8PxWEGKwfPMw7F+f4Y6l9+LeJvCOgChZR1mM
- hODemhe8pbeyFMSSZPWQZq1XAexMDMbVeQJBALJgmZ7pzrqp7dgd+tw0MCF7XQBO
- KtuCJNcb3a3GeHUPYFGiPMEddYMfFRJlDAdilNOsG1SXaOmPO20fbFgLt1kCQQCq
- iDcisZNIEPJElGODaj1e0pVxjR3USAHX1j3CJKSbVqxIBmvcEZugOsafHxuXVyFb
- HKp3HyhlohEu0QUYYakhAkEA7P5Fdw0JryJC2S7QodiTIXOfhn6WEtuVCX+Nz8Lc
- ue+ojBfrIMWHzfGWBc+JjFHbjV/XtdLpebnr5Pay1oZtRA==
- -----END RSA PRIVATE KEY-----
- """
- def sign(key, data):
- RSA.import_key
- private_key = RSA.importKey(key)
- cipher = PKCS1_v1_5.new(private_key)
- h = SHA256.new(data)
- signature = cipher.sign(h)
- return base64.b64encode(signature)
- ts = "1595319666236"
- baseUrl = "https://api-gateway.walmart.com/v3/feeds"
- consumerId = "123456"
- def main():
- httpMethod = "GET"
- timestamp = ts # 测试需要
- stringToSign = consumerId + "\n" + baseUrl + "\n" + httpMethod + "\n" + timestamp + "\n"
- r = sign(private_key,stringToSign.encode())
- print(r)
- if __name__ == "__main__":
- main()
评论
发表评论