1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natima [27]
3 years ago
12

Write a function isPrime of type int -> bool that returns true if and only if its integer parameter is a prime number. Your f

unction need not behave well if the parameter is negative.

Computers and Technology
1 answer:
PolarNik [594]3 years ago
5 0

Answer:

import math

def isPrime(num):

 

   if num % 2 == 0 and num > 2:

       return False

   for i in range(3, int(math.sqrt(num)) + 1, 2):

       if num % i == 0:

           return False

   return True

Explanation:

The solution is provided in the python programming language, firstly the math class is imported so we can use the square root method. The first if statement checks if the number is even and greater than 2 and returns False since all even numbers except two are not prime numbers.

Then using a for loop on a range (3, int(math.sqrt(num)) + 1, 2), the checks if the number evenly divides through i and returns False otherwise it returns True

see code and output attached

You might be interested in
If your pulse is higher than your Target Heart Rate during exercise, what should you do?
vodomira [7]
If your heart rate exceeds 185 beats per minute during exercise, it is dangerous for you. Your target heart rate zone is the range of heart rate that you should aim for if you want to become physically fit. It is calculated as 60 to 80 percent of your maximum heart rate.
8 0
2 years ago
Read 2 more answers
One of the earlier applications of crypto-graphic hash functions was the storage of passwords to authenticate usersin computer s
vagabundo [1.1K]

Answer: provided in the explanation part.

Explanation:

This is actually quite long but nevertheless i will make it as basic as possible.

Question (a)  

Attack A:

One way property of hash means that we can't find the input string if given the hash value. The calculation of hash from input string is possible but it is not possible to calculate the input string when given the hash. If the hash function is properly created to have one-way property then there is no way of finding the exact input string. So this attack won't work as the one-way property of hash function can't be broken if the hash function is properly created.

Attack B:

Suppose h() is the hash function. And h(x) = m where x is the string and m is the hash. Then trying to find another string y such that h(y) = m is called finding out the second pre-image of the hash.

Although we can't know the exact initial string for sure, we can by using brute force method find out a second preimage.

This attack will take a very long time. It has the time complexity of 2n. It requires the attacker to have an idea about the kind of passwords that might be used and then brute force all of them to find the string that has the same hash. Each try will have a chance of 1/2n to succeed.

Rainbow attack using rainbow table is often used for such brute-force attack. This comprises a rainbow table which contains passwords and their pre-hashed values.

Therefore, it is not possible to determine the second preimages of h so easily.

Attack C:

Collisions refer to finding out m and m' without knowing any of them. Finding out collisions is easier than finding preimages. This is because after finding out 2n pairs of input/output. The probability of two of them having the same output or hash becomes very high. The disadvantage is that we can't decide which user's hash to break. However, if I do not care about a particular user but want to get as many passwords as possible, then this method is the most feasible.

It has the time complexity of 2n/2.

Hence, this is the attack which has the most success rate in this scenario.

Question (b)

The brute force way of finding out the password usually involves using a rainbow attack. It comprises a rainbow table with millions of passwords and their hashes already computed. By matching that table against the database, the password can be recovered.

Therefore it is often preferred to salt the password. It means we add some random text to the password before calculating the hash.

The salts are usually long strings. Although users usually do not select long passwords, so a rainbow table with hashes of smaller passwords is feasible. But once salt is used, the rainbow table must accommodate for the salt also. This makes it difficult computationally. Although password might be found in the rainbow table. The salt can be anything and thus, make brute-force a LOT more difficult computationally.

Therefore salt is preferred to be added to passwords before computing their hash value.

Question (c)

A hash output length of 80 means there can be exactly 280 different hash values. This means there is at least one collision if 280+1 random strings are hashed because 280 values are used to accommodate all the possible strings. It is not hard with today's computation power to do match against more than this many strings. And doing so increases the probability of exposing a probable password of a user.

Hence, 80 is not a very secure value for the hash length.

cheers i hope this helps!!!!

6 0
3 years ago
How does Frankenstein feel about his creation?
velikii [3]

Answer:

he just regrets that he made a monster and deeply feels guilty that it is in pain of reliving

Explanation:

8 0
3 years ago
Employees at the Red Bluff Golf Club & Pro Shop have the opportunity to become certified trainers if they log enough hours.
vodka [1.7K]

Answer:

Following are the solution to this question:

Explanation:

Some of the data is missing in the question, which is defined in the attached file. Please find it.

Follows are the formula which is used in the question:

  • EmployeeAnalysis Worksheet IF(C5>49,"Certified","Not Certified")
  • Transactions Worksheet IF(F10="No","",0.07)

In the first condition, it checks "C5" is greater than 49 if the condition is true, it will give "Certified" otherwise, it will give "Not Certified".

In the second condition, it checks "F10" is equal to "No" if the condition is true, it will give a blank or space otherwise, it will give "0.07".

3 0
2 years ago
You are given two processors P1 and P2 that execute the same instruction set but have different architectures. The instructions
mafiozo [28]

The answer & explanation for this question is given in the attachment below.

3 0
3 years ago
Other questions:
  • Integrated circuits are made up of _____ that carry the electrical current.
    14·1 answer
  • What kind of fragment is near the computer?
    14·1 answer
  • How do you measure objects and re-size them in tinkercad? I need it in steps.
    7·1 answer
  • What are two variables is figure 1 comparing
    10·1 answer
  • What's the main piece of information you look for in an e-mail message you're investigating??
    14·2 answers
  • The simplest element that exists is only one proton and one electron. It is what stars are made of. It's symbol is "H". What is
    9·1 answer
  • Write a couple of paragraphs about the usefulness of computer​
    5·1 answer
  • How to improve a poor game design puzzles
    11·1 answer
  • In Outlook 2016, the Tell Me function can be accessed by
    15·2 answers
  • What operating system do most users use?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!