Question

we have a password that consists of n digits(0….9) Create a swift program that let the...

we have a password that consists of n digits(0….9)
Create a swift program that let the user enters n and then find how many different password combination we could have and print no of them (upon the user choice )randomly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import Foundation

func randomPassword(length: Int) -> String {

    let chars : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_+{}[]-=:?><,./"
    let len = UInt32(chars.length)

    var Passwords = ""

    for _ in 0 ..< length {
        let rand = arc4random_uniform(len)
        var nextChar = chars.character(at: Int(rand))
        Passwords += NSString(characters: &nextChar, length: 1) as String
    }

    return Passwords
}


print("Enter the number of digits[0-9]: ")
let n = Int(readLine(strippingNewline: true)!)! // taking integer input from user
print(n)

// We assume the password contains all the printable characters of ascii set i.e 95

let nn = Double(n) // First converting the integer value to use the pow function
let number = pow(95.0, nn) // calculating the number of combinations possible

print("The number of combinations possible for", n , "digits are:", number)

print("Enter the number of passwords to show: ")
let N = Int(readLine(strippingNewline: true)!)! // taking integer input from user

// Using for loop to print all the passwords

for _ in 1...N{
    let pass = randomPassword(length : n)
    print(pass)
}

Add a comment
Know the answer?
Add Answer to:
we have a password that consists of n digits(0….9) Create a swift program that let the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 8 A password consists of 5 digits of 0 to 9. In the worst case,...

    QUESTION 8 A password consists of 5 digits of 0 to 9. In the worst case, how many combinations does a hacker must try in order to break the password brutal force? Write your answer in exact Integer QUESTION Use Cesar cipher with offset 21 to encrypt "UHD"

  • A password consists of 4 letters among 26 lower-case English alphabet letters and 10 digits: 0,1,...,9....

    A password consists of 4 letters among 26 lower-case English alphabet letters and 10 digits: 0,1,...,9. (i) How many different passwords that contain at least one digit can be formed? (ii) How many different passwords that contain at least one digit and at least one letter can be formed?

  • You need to have a password with 4 letters followed by 4 even digits between 0...

    You need to have a password with 4 letters followed by 4 even digits between 0 and 9 , inclusive. If the characters and digits cannot be used more than once, how many choices do you have for your password?

  • You need to have a password with 5 letters followed by 3 odd digits between 0...

    You need to have a password with 5 letters followed by 3 odd digits between 0 and 9, inclusive. If the characters and digits cannot be used more than once, how many choices do you have for your password

  • 5. A hacker is trying to guess a password. They have worked out that the password has length 8, being a mix of 1 upperc...

    5. A hacker is trying to guess a password. They have worked out that the password has length 8, being a mix of 1 uppercase letter (from {A. . . . ,7), 5 lowercase letters (from {a, . . . ,:) and 2 digits (from 10,...,91). They do not know in which order these symbols occur in the password. [In this question, answers may be given as a product of integers, without evaluating further.] a) How many passwords fit this...

  • A CERTAIN program to user's password containing rules such as least n length, one uppercase, lowercase,...

    A CERTAIN program to user's password containing rules such as least n length, one uppercase, lowercase, one digit and white space is given as the code down below. So, simiiar to those rules, I need the code for the following questions post in pictures such as no more three consecutive letters of English alphabets, password should not contain User name and so on. //GOAL: To learn how to create that make strong passwords //Purpose: 1)To learn some rules that makes...

  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • Using Swift playground and / or the command line for macOS (open Xcode, create a new...

    Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...

  • Part 1: Is this Crazy Password Valid? A good password (in this strange system) should have...

    Part 1: Is this Crazy Password Valid? A good password (in this strange system) should have the following properties: Rule 1: The password should be between 4 and 25 characters inclusive, starting with a letter. Rule 2. The password should not be contained in a list (selected by the user) that contains passwords commonly used by many people thus making these passwords easy to guess. Comparisons with passwords from the list of common passwords should be case insensitive. For example,...

  • 1- If four alphabets are to be chosen from L, M, N, O, P, Q such...

    1- If four alphabets are to be chosen from L, M, N, O, P, Q such that repetition is not allowed then in how many ways it can be done? 2- Sally must choose a 5-digit PIN. Each digit can be chosen from 0 to 9 and the same digit can be used repeatedly. How many possible PIN numbers can be created? 3- Jenny has 8 tops, 5 bottoms, 2 belts, and 2 bracelets. Assuming that everything matches, how many...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT