簡體   English   中英

如何為使用 Python 創建的隨機密碼生成器編寫偽代碼?

[英]How to write Pseudocode for Random Password Generator created using Python?

我需要為下面的隨機密碼生成器編寫一個偽代碼。 我該如何編寫偽代碼 請幫幫我。 謝謝你。

import random
import string

print('hello, Welcome to Password generator!')

l = False
while not l:
    length = int(input('\nEnter the length of password: '))
    if length < 8 :
        print('You password length is too short(must be more than 8 character)')
        print(length, "is the length of your password")
    elif length > 16:
            print('You password length is too long(must be less than 17 character)')
            print(length, "is the length of your password")
    else:
            print('You password length looks good')
            break

lower = string.ascii_lowercase
upper = string.ascii_uppercase
num = string.digits
symbols = string.punctuation

all = lower + upper + num + symbols

temp = random.sample(all,length)

password = "".join(temp)

print(password)

這夠好嗎?

IMPORT random
IMPORT string

OUTPUT('hello, Welcome to Password generator!')

SET l TO False
WHILE not l:
    SET length TO int(INPUT('\nEnter the length of password: '))
    IF length < 8 :
        OUTPUT('You password length is too short(must be more than 8 character)')

        OUTPUT(length, "is the length of your password")

    ELSEIF length > 16:

            OUTPUT('You password length is too long(must be less than 17 character)')

            OUTPUT(length, "is the length of your password")

    ELSE:
            OUTPUT('You password length looks good')
            break

SET lower TO string.ascii_lowercase
SET upper TO string.ascii_uppercase
SET num TO string.digits
SET symbols TO string.punctuation
SET all TO lower + upper + num + symbols
SET temp TO random.sample(all,length)
SET password TO "".join(temp)
OUTPUT(password)

或者這個:

DECLARE length<-int(input('\nEnterthelengthofpassword:')) : INTEGER
import random
import string

OUTPUT 'hello, Welcome to Password generator!'

l<-False
WHILE not l DO
INPUT length<-int(input('\nEnterthelengthofpassword:'))
    IF length < 8 
        THEN
        OUTPUT 'You password length is too short(must be more than 8 character'
        OUTPUT length, "is the length of your password"
    ENDIF
    elif length > 16:  //You will need to change this to CASE OF
            OUTPUT 'You password length is too long(must be less than 17 character'
            OUTPUT length, "is the length of your password"
    ELSE
            OUTPUT 'You password length looks good'
            break  //This might be better as a repeat loop
ENDWHILE

lower<-string.ascii_lowercase
upper<-string.ascii_uppercase
num<-string.digits
symbols<-string.punctuation

all<-lower + upper + num + symbols

temp<-random.sample(all,length)

password<-"".join(temp)

OUTPUT password

Process finished with exit code 0

偽代碼是一種代碼,旨在顯示特定算法的步驟。 對於這個算法,它可能看起來像這樣。

output "Welcome"
l := false
while l is not true do
    length := int value of input("Enter length of password: ")
    if length < 8 do
        output "Your password is too short"
    else if length > 16 do
        output "Your password is too long"
    else do
        output "Password length looks good"
        break from loop
    endif
endwhile

lower := array of lowercase letters
upper := array of uppercase letters
numbers := array of digit characters
symbols := array of punctuation characters

all := lower combined with upper combined with numbers combined with symbols
temp := random sample of all, with length len
password := join "" with temp
output password

有關偽代碼的更多閱讀,請查看此鏈接: https://en.wikipedia.org/wiki/Pseudocode

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM