Computers and Technology
Write a JAVA program that reads from the keyboard a small password and then offers two options:1. enter your name and a filename to save or2. enter a file name to load.With the option 1 proceed to save to the file an encrypted version of your name (details below), with the option 2 proceed to load the information from the file and decrypt the name and print it to the screen. The options 1 and 2 are in reverse (1 saves the encrypted information to the file, 2 decrypts the information from the file). Details of the encryption: Say your name is Andrei and you chose the password 1234, then you do XOR between the ASCII code for A (first letter in your name) and the ASCII code for 1(first letter in your password), I will denote this operation (A,1) then you do XOR between n and 2 (n,2) (second letter in your name with second letter in password) and so on, thus we will have the following operations to perform: (A,1) (n,2) (d,3) (r,4) (e,1) (i,2). Obviously, if you would choose the password qwer then the XOR operations will be between the following pairs: (A,q)(n,w)(d,e)(r,r)(e,q)(i,w). The trick is that the encrypted text can be decrypted due to the following property of XOR: A XOR B=C; C XOR B=A, thus if I have the results of the XOR operations in the file (and this is your name encrypted) then it is sufficient to do XOR with the same password (with the same ASCII codes) and I will get back the original string. For example, with the first password, (A XOR 1) XOR 1 =A, (n XOR 2) XOR 2=n and so on: ((A,1),1) ((n,2),2) ((d,3),3) ((r,4),4) ((e,1),1) ((i,2),2)= A n d r e i.
. Within function empty(), write the Boolean expression to determine if the list is empty. Do not put spaces in your answer. That is, X=-Y is okay, but X == Y is not. 2. True or False: Removing the last element from the list conditionally requires setting sentinel._next to nullptr. 3. Implement push_front(data) in 5 lines of code. Do not separate identifiers and operators with spaces, but do separate identifiers with a single space. That is, X=Y and new Data are okay, but X = Y, newData , and new Data are not. Don't forget your semicolon. template void DuublyLinkeList:: push_front( const 1 & data) { // 1. Get and initialize a new dynamically created Node called newNode // 2. Set the new node's next pointer to point to the first node in the list // 3. Set the new node's previous pointer to the list's dummy node // 4. Set the first node's previous pointer to point to the new node // 5. Set the dummy node's next pointer to point to the new node } ******** ****** ** Class DoublyLinkedList - a very basic example implementation of the Doubly Linked List Abstract Data Type ** This file provides a one-dummy node, circular implementation of the DoublyLinkedList interface ** Empty (size = 0): V V I prev | not used | next ** sentinel A A A begin( (aka head, sentinel.next) tail (aka sentinel.prev) end size = 3: -+ 1 +- ------ I - prev | not used | next |----> prev | data | next |----> prev data | next prev | data | next |---- -- | sentinel A A A A 1 1 1. 1. end() tail (aka sentinel.prev) begin() (aka head, sentinel.next) **** */ #pragma once #include size_t #include length_error, invalid argument #include "DoublyLinkedlist.hpp" ******** *******/ ***** ******** ********/ /***** ** DoublyLinkedList with one dummy node function definitions namespace CSUF::CPSC131 { /**** ** A doubly linked list's node ************ template struct DoublyLinkedList::Node { Node() = default; Node const Data_t & element ) : _data( element) {} Data_t_data; linked list element value Node * _next = this; next item in the list Node * _prev = this; previous item in the list 11 // ************ *********** ***/ /****** ** A doubly linked list's private data implementation template struct DoublyLinkedList::PrivateMembers A specific implementation's private members (attributes, functions, etc) { Node _sentinel; dummy node. The first node of the list (_head) is at _sentinel->next; Node *& _head = _sentinel._next; An easier to read alias for the list's head, which is a pointer-to-Node Node *& _tail = _sentinel._prev; last element in the list. tail->next always points to _sentinel std::size_t _size = 0; number of elements in the collection }; template typename DoublyLinkedList::Iterator DoublyLinkedList:.insertBefore( const Iterator & position, const Data_t & element ) { Node * newNode = new Node( element ); create and populate a new node newNode->_next = position(); newNode->_prev = position->_prev; position()->_prev->_next = newNode; position() ->_prev = newNode; ++self->_size; return newNode; } template typename DoublyLinkedList::Iterator DoublyLinkedList:.remove( const Iterator & position ) { if( empty ) throw std:: length_error ( "Attempt to remove from an empty list ); if(position == end()) throw std::invalid_argument( "Attempt to remove at an invalid location" ); position()->_next->_prev = position()->_prev; position->prev->next = position ->next; --self->_size; Iterator returnNode( position()->_next ); return the node after the one removed delete position(); delete what used to be the old node return returnNode; } template typename DoublyLinkedList::Iterator DoublyLinkedList::end() const { return &self->_sentinel; } template typename DoublyLinkedList::Iterator DoublyLinkedList::rend() { return &self->_sentinel; } const