
Concept explainers
using System.Collections.Generic;
using System.IO;
using System.Xml;
using Packt.Shared;
using static System.Console;
using static System.IO.Path;
using static System.Environment;
namespace Exercise02
{
class Program
{
static void Main(string[] args)
{
WriteLine("You must enter a password to encrypt the sensitive data in the document.");
WriteLine("You must enter the same passord to decrypt the document later.");
Write("Password: ");
string password = ReadLine();
// define two example customers and
// note they have the same password
var customers = new List<Customer>
{
new Customer
{
Name = "Bob Smith",
CreditCard = "1234-5678-9012-3456",
Password = "Pa$$w0rd",
},
new Customer
{
Name = "Leslie Knope",
CreditCard = "8002-5265-3400-2511",
Password = "Pa$$w0rd",
}
};
// define an XML file to write to
string xmlFile = Combine(CurrentDirectory,
"..", "protected-customers.xml");
var xmlWriter = XmlWriter.Create(xmlFile,
new XmlWriterSettings { Indent = true });
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("customers");
foreach (var customer in customers)
{
xmlWriter.WriteStartElement("customer");
xmlWriter.WriteElementString("name", customer.Name);
// to protect the credit card number we must encrypt it
xmlWriter.WriteElementString("creditcard",
Protector.Encrypt(customer.CreditCard, password));
// to protect the password we must salt and hash it
// and we must store the random salt used
var user = Protector.Register(customer.Name, customer.Password);
xmlWriter.WriteElementString("password", user.SaltedHashedPassword);
xmlWriter.WriteElementString("salt", user.Salt);
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
WriteLine();
WriteLine("Contents of the protected file:");
WriteLine();
WriteLine(File.ReadAllText(xmlFile));
}
}
}


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- c#arrow_forwardMicrosoft Visual C# 7th edition, debugging 9-2 Instruction: The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. // Creates a Breakfast class // and instantiates an object // Displays Breakfast special information using System; using static System.Console; using System.Globalization; class DebugNine2 { static void Main() { Breakfast special = new Breakfast("French toast, 4.99); //Display the info about breakfast WriteLine(INFO); // then display today's special WriteLine("Today we are having {1} for {1}", special.name, special.Price.ToString("C2", CultureInfo.GetCultureInfo("en-US"))); } } class Breakfast { public string INFO = "Breakfast is the most important meal of the day."; // Breakfast constructor requires a // name, e.g "French toast", and a price public Breakfast(string name, double price) { name = name; price = price; } public string Name…arrow_forwardsource code: import java.util.*;import java.io.*; public class Main { static File text = new File("/Users/.../Desktop/sourceCode.txt"); static FileInputStream keyboard; static int charClass; static char lexeme[] = new char[100]; //stores char of lexemes static char nextChar; static int lexLen;// length of lexeme static int token; static int nextToken; // Token numbers static final int LETTER = 0; static final int DIGIT = 1; static final int UNKNOWN = 99; static final int INT_LIT = 10; static final int IDENT = 11; static final int ASSIGN_OP = 20; static final int ADD_OP = 21; static final int SUB_OP = 22; static final int MULT_OP = 23; static final int DIV_OP = 24; static final int LEFT_PAREN = 25; static final int RIGHT_PAREN = 26; public static void main(String[] args) { try{ keyboard = new FileInputStream(text); getChar(); do { lex(); }while…arrow_forward
- using System; class Program { publicstaticvoid Main(string[] args) { int number = 1; while (number <= 88) { Console.WriteLine(number); number = number + 2; } int[] randNo = newint[88]; Random r = new Random(); int i=0; while (number <= 88) { randNo[i] = number; number+=1; i+=1; } for (i = 0; i < 3; i++) { Console.WriteLine("Random Numbers between 1 and 88 are " + randNo[r.Next(1, 88)]); } } } this code counts from 1-88 in odds and then selects three different random numbers. it keeps choosing 0 as a random number everytime. how can that be fixed?arrow_forwardFix all the errors and send the code please // Application looks up home price // for different floor plans // allows upper or lowercase data entry import java.util.*; public class DebugEight3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String entry; char[] floorPlans = {'A','B','C','a','b','c'} int[] pricesInThousands = {145, 190, 235}; char plan; int x, fp = 99; String prompt = "Please select a floor plan\n" + "Our floorPlanss are:\n" + "A - Augusta, a ranch\n" + "B - Brittany, a split level\n" + "C - Colonial, a two-story\n" + "Enter floorPlans letter"; System.out.println(prompt); entry = input.next(); plan = entry.charAt(1); for(x = 0; x < floorPlans.length; ++x) if(plan == floorPlans[x]) x = fp; if(fp = 99) System.out.println("Invalid floor plan code entered")); else { if(fp…arrow_forwardThe provided file has syntax and/or logical errors. Determine the problem and fix the program.arrow_forward
- Question 37 public static void main(String[] args) { Dog[] dogs = { new Dog(), new Dog()}; for(int i = 0; i >>"+decision()); } class Counter { private static int count; public static void inc() { count++;} public static int getCount() {return count;} } class Dog extends Counter{ public Dog(){} public void wo(){inc();} } class Cat extends Counter{ public Cat(){} public void me(){inc();} } The Correct answer: Nothing is output O 2 woofs and 5 mews O 2 woofs and 3 mews O 5 woofs and 5 mews Oarrow_forwardSemaphores: Select all of the following statements that are true. The operations P (Test) and V (Signal) can be interrupted. The operations P (Test) and V (Signal) run in the operating system's user mode. The values of binary semaphores are restricted to 0 and 1. Counting semaphores are used to manage limited resources and the corresponding access to them. Semaphores can be used to synchronize certain operations between processes. When accessing the list of a semaphore, the FIFO principle should be preferred to the LIFO principle.arrow_forwardpublic class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.arrow_forward
- python class Student:def __init__(self, first, last, gpa):self.first = first # first nameself.last = last # last nameself.gpa = gpa # grade point average def get_gpa(self):return self.gpa def get_last(self):return self.last def to_string(self):return self.first + ' ' + self.last + ' (GPA: ' + str(self.gpa) + ')' class Course:def __init__(self):self.roster = [] # list of Student objects def drop_student(self, student):# Type your code here def add_student(self, student):self.roster.append(student) def count_students(self):return len(self.roster) if __name__ == "__main__":course = Course() course.add_student(Student('Henry', 'Nguyen', 3.5))course.add_student(Student('Brenda', 'Stern', 2.0))course.add_student(Student('Lynda', 'Robinson', 3.2))course.add_student(Student('Sonya', 'King', 3.9)) print('Course size:', course.count_students(),'students')course.drop_student('Stern')print('Course size after drop:', course.count_students(),'students')arrow_forwardComputer Science Part C: Interactive Driver Program Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.arrow_forwardimport java.util.Scanner; public class Inventory { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); InventoryNode headNode; InventoryNode currNode; InventoryNode lastNode; String item; int numberOfItems; int i; // Front of nodes list headNode = new InventoryNode(); lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ) { item = scnr.next(); numberOfItems = scnr.nextInt(); currNode = new InventoryNode(item, numberOfItems); currNode.insertAtFront(headNode, currNode); lastNode = currNode; } // Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





