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
lys-0071 [83]
3 years ago
11

Implement function easyCrypto() that takes as input a string and prints its encryption

Computers and Technology
1 answer:
jasenka [17]3 years ago
4 0

Answer:

The program written in python is as follows;

import string

def easyCrypto(inputstring):

      for i in range(len(inputstring)):

             try:

                    ind = string.ascii_lowercase.index(inputstring[i])

                    pos = ind+1

                    if pos%2 == 0:

                           print(string.ascii_lowercase[ind-1],end="")

                    else:

                           print(string.ascii_lowercase[ind+1],end="")

             except:

                    ind = string.ascii_uppercase.index(inputstring[i])

                    pos = ind+1

                    if pos%2 == 0:

                           print(string.ascii_uppercase[ind-1],end="")

                    else:

                           print(string.ascii_uppercase[ind+1],end="")

anystring = input("Enter a string: ")

easyCrypto(anystring)

Explanation:

The first line imports the string module into the program

import string

The functipn easyCrypto() starts here

def easyCrypto(inputstring):

This line iterates through each character in the input string

      for i in range(len(inputstring)):

The try except handles the error in the program

             try:

This line gets the index of the current character (lower case)

                    ind = string.ascii_lowercase.index(inputstring[i])

This line adds 1 to the index

                    pos = ind+1

This line checks if the character is at even position

                    if pos%2 == 0:

If yes, it returns the alphabet before it

                           print(string.ascii_lowercase[ind-1],end="")

                    else:

It returns the alphabet after it, if otherwise

                           print(string.ascii_lowercase[ind+1],end="")

The except block does the same thing as the try block, but it handles uppercase letters

<em>              except: </em>

<em>                     ind = string.ascii_uppercase.index(inputstring[i]) </em>

<em>                     pos = ind+1 </em>

<em>                     if pos%2 == 0: </em>

<em>                            print(string.ascii_uppercase[ind-1],end="") </em>

<em>                     else: </em>

<em>                            print(string.ascii_uppercase[ind+1],end="") </em>

<em />

The main starts here

This line prompts user for input

anystring = input("Enter a string: ")

This line calls the easyCrypto() function

easyCrypto(anystring)

You might be interested in
How are most gamepads installed on devices?
Doss [256]

Answer:

Plug and Play

Explanation:

most modern game pads are you just need to plug into a port and then you are free to use without any setting up.

3 0
2 years ago
A computer with a domain name is called a what
Irina18 [472]
A domain refers to a group of computers that are part of a network and share network resources, like your home<span> computers all linked together sharing a printer. The user logs in to the domain and gains access to the resources. Several systems may be involved. The computer itself is referred to as a server.</span>
6 0
3 years ago
Read 2 more answers
What is the default shell in linux called?
AfilCa [17]
After logged into the terminal a user will get the interface to access the system it is called shell<span>. The </span>default shell in Linux<span> is BASH. Thus the correct option is BASH.</span>
7 0
4 years ago
Michelle is writing an assignment on programming language. Help Michelle complete the following statement that describes the inp
Oliga [24]

Input statements allow the user to enter data that a program uses to perform necessary computations. Users enter the data when they <u>encounter the statements like the scanf() or gets() functions in the program.</u>

<u>Explanation:</u>

The scanf() is the function that is used to take inputs from the user with the help of the standard input device,i.e, the keyboard.

scanf() function is capable of taking any data type as an input, though it has to be specified first like %d for integers, %s for strings and %f for floating-point type. The gets() function can only take a string as an input.

3 0
4 years ago
On tablets and smartphones, what feature can be used that can erase the contents of the device if lost or stolen?
Artemon [7]
You could use the ADM website from a computer or any other device (that is not missing)
 <span />
4 0
3 years ago
Other questions:
  • Which type of software is created and updated by a worldwide community of programmers and is available for​ free?
    14·1 answer
  • When should an individual consider entering parenthood?
    5·1 answer
  • Cómo pongo un tomo de llamada SIN PAGAR?
    7·1 answer
  • Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
    15·1 answer
  • What is the significance of both RAID and IP technologies as precursors to the SAN environment?
    11·1 answer
  • A word feature that joins a data source and a main document to create a customized document is: combine documents. data merge. m
    8·1 answer
  • Using a single formatting _______ helps to make reading researched information easier; it lets the reader know what to expect.
    7·1 answer
  • The Register Set that stores temporary results related to the computations are<br>​
    7·1 answer
  • What is the easiest way to defeat ganon in BOTW?
    11·2 answers
  • To freeze rows 1 and 2, and columns 1, 2, and 3, which cell should you highlight before selecting freeze panes?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!