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
Gre4nikov [31]
3 years ago
4

Modify the scripts of Projects 1 and 2 to encrypt and decrypt entire files of text. An example of the program interface is shown

below: Enter the input file name: encrypted.txt Enter the output file name: a Enter the distance value: 3
Computers and Technology
1 answer:
STatiana [176]3 years ago
8 0

Answer:

The following are the program in the Python Programming Language.

#get input from the user

inputFile = input("Enter the input file name: ")

#get input from the user

outputFile = input("Enter the output file name: ")

#get input from the user

dist = int(input("Enter the distance value: "))

#open file for only read

infile = open(inputFile, "r")

#open file for only write

outfile = open(outputFile, "w")

#read lines from the file

get = infile.readlines()

#set the for loop

for text in get:

#set variable as empty string variable

code = ""

#then, set the for loop

for char in text:

#store the unicode of the variable

Value = ord(char)

 #perform calculation

cipher = Value + dist

#check that the calculation is greater than 127

      f(cipher > 127):

#then, again perform another calculation

cipher = dist - (127 - Value | 1)

#convert it into the character

code += chr (cipher)

#write the following converted character in it.

 outfile.write(code)

Explanation:

The following are the description of the program.

  • Firstly, set three variables 'inputfile', 'outputfile' and 'dist' that get input from the user, the first one gets the input file name, second one gets the output file name and the last one gets the distance.
  • Then, set two variables 'infile' and 'outfile' which open the 1st file for only read and second one open file for only write then, set the variable 'get' that read the line from the read-only file.
  • Set the for loop that stores that lines in the variable 'text' and then, set the empty string type variable 'code'. Set the for loop that store the variable of the 'text' in the 'char' then, set the variable 'Value' that store the Unicode of the variable 'char' and perform calculation between the variables 'Value' and 'char' and store it in the variable 'cipher'.
  • Then, set the if conditional statement that checks the variable 'cipher' is greater than 127 and perform the another calculation, then convert the variable 'cipher' into the character and store it in the variable 'code'.
  • Finally, we close all the following open files.
You might be interested in
C++ Code Outputs.
mojhsa [17]

Answer:

#include

#include

#include

#include

using namespace std;

struct courseInfo{

string name;

int unit;

char grade;

};

struct Student {

string fName;

string lName;

string idNumber;

courseInfo courses[2];

int unitCompleted;

double gpa;

};

Student s;

bool openFile(ifstream &in);

void Print_info_one(Student s);

void Read_info(Student &s);

float Find_points(char c) ;

bool openFile(ifstream &inFile){

string line;

int i=0,k=0;

string fName="", lname="", id="", name1="", name2="";

char grade1, grade2;

int unit1, unit2;

if (inFile.is_open())

{

while (getline(inFile, line))

{

while (line[i] != ',')

{

fName += line[i];

i++;

}

i++;

i++;

while (line[i] != ' ')

{

lname += line[i];

i++;

}

i++;i++;

while (line[i] != ' ')

{

id += line[i];

i++;

}

i++;

int count=0;

while (count <2)

{

name1 += line[i];

i++;

if(line[i] == ' ' ) count++;

}

i++;

grade1 = line[i];

i++;i++;

unit1 = line[i]-'0';

i++;i++;

count=0;

while (count <2)

{

name2 += line[i];

i++;

if(line[i] == ' ' ) count++;

}

i++;

grade2 = line[i];

i++;i++;

unit2 = line[i]-'0';

}

inFile.close();

s.fName = fName;

s.lName = lname;

s.idNumber = id;

s.courses[0].name = name1;

s.courses[0].grade = grade1;

s.courses[0].unit = unit1;

s.courses[1].name = name2;

s.courses[1].grade = grade2;

s.courses[1].unit = unit2;

s.unitCompleted = unit1 + unit2;

s.gpa = (unit1*Find_points(grade1) + unit2*Find_points(grade2))/(unit1+unit2);

}

else

{

cout << "Error reading file\n";

return false;

}

return true;

}

void Print_info_one(Student s){

cout << "Name: " << s.fName << ", " << s.lName << " ID Number: " << s.idNumber << " Course 1 Name: " << s.courses[0].name << " Grade: "

<< s.courses[0].grade << " Units: " << s.courses[0].unit << " Course 2 Name: " << s.courses[1].name << " Grade: "

<< s.courses[1].grade << " Units: " << s.courses[1].unit << " Unit completed: " << s.unitCompleted << " GPA:" << s.gpa << endl;

}

void Read_info(Student &s){

}

float Find_points(char grade){

switch (grade)

{

case 'A':

return 4.0;

break;

case 'B':

return 3.0;

break;

case 'C':

return 2.0;

break;

case 'D':

return 1.0;

break;

case 'F':

return 0;

break;

default:

break;

}

return 0;

}

int main() {

ifstream inFile;

std::fstream fs;

fs.open ("input.txt", std::fstream::in );

Print_info_one(s);

return 0;

Explanation:

5 0
3 years ago
Write an algorithm and draw flowchart to print 30 terms in the following sequence
frozen [14]

Answer:

9,-10,11,-12,13,-14,15,-16,17,-18,19,-20,21,-22,23,-24,25,-26,

27,-28,29,-30

Explanation:

It comes as positive and then as a negative number and continues in the same format.

Hope it helps....

4 0
3 years ago
Read 2 more answers
Which of these is NOT a cloud-based system?
-BARSIC- [3]
Skype isn't a cloud based system. Cloud based systems are online storage systems. Google Drive, Dropbox, and SkyDrive are all pieces of software which allow you to store data on a remote server over the internet. Skype is just a program.
7 0
3 years ago
In the center pane of the __________, the direction of each arrow indicates the direction of the TCP traffic, and the length of
7nadin3 [17]

Answer:

The answer is B (Flow Graph Analysis results)

Explanation:

Flow Graph Analysis results is a graphical representation of control flow which is process oriented, it shows all the paths through a program during its execution.

4 0
4 years ago
Solution is c language please help me.​
nordsb [41]

Explanation:

in c++

#include<iostream.h>

#using namespace std;

main()

{ float x,y,z,r, phi, theta;

cout<<" enter the value of x";

cin>>x;

cout<<" enter the value of y";

cin>>y;

cout<<" enter the value of z";

cin>>z;

r = (sqrt(pow(x,2) + pow(y, 2) + pow(z, 2)));

phi = (asinf(y/r)*180.0f)/PI;

theta = (asinf(-x/(r*cosf(phi)))*180.0f)/PI;

cout<<"The radius r= "<<r;

cout<<"The phi angle= "<<phi;

cout<<"The theta angle= "<<theta;

return 0;

}

4 0
3 years ago
Other questions:
  • Imagine the world in 2030 and write a letter to your future self. Be sure to mention things that you think your future self woul
    8·1 answer
  • A restaurant bill comes to $28.35. Find the total cost if the tax is 6.25% and a 20% tip is left on the amount before tax.​
    6·1 answer
  • Ingrid started speaking about her slide presentation. When she clicked to th
    11·2 answers
  • Algorithmic Complexity: what is the asymptotic complexity (Big-O) of each code section? Identify the critical section of each.\
    8·1 answer
  • Francis has created a new program. However, Francis used some objects from another program to run methods in the current program
    14·2 answers
  • A general rule for printing is to use _____ fonts for headlines and serif fonts for body text
    6·1 answer
  • Three positive impacts of computer technology in our society.​
    7·2 answers
  • What does c++ programming mean?
    7·1 answer
  • Advantages of monolithic operating system? ​
    6·1 answer
  • What controls can be found on the File tab of Microsoft PowerPoint? Check all that apply. Help Print Track Open Insert Save
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!