Name: ____________________________________________________ Alpha: ________________________

  1. [10pts] Fill in the blank in the code so that the output is correct. Note: do not use any string operation, any loop, or any if statement. Use bit operations.
    
    #===========================================================================
    # fill in the blank: Write a function get_at
    # input 
    #  - n: an 8-bit integer
    #  - i: an integer between 0 and 7 (inclusive)
    # output 
    #    the i-th bit of n (as an integer) 
    # WARNING:
    #  - You are only allowed to use the following operations:
    #      bitwise-and, bitwise-or, bitwise-xor, shift-left, 
    #      shift-right, parenthesis, addition, subtraction.
    #    All the other operations (e.g., multiplication, string, list, etc.) 
    #       are prohibited. 
    #
    #  - The function should work correctly for any 8-bit integer n. 
    def get_at(n, i):
    
       return _________________________________________________ 
    
    
    Here are sample runs. Carefully inspect the sample run to see how the indexing of i works
    
    >>> for i in range(8):
    ...   print( get_at(0b11101100, i) )
    ... 
    1
    1
    1 
    0
    1
    1 
    0 
    0
    
    
    >>> print( get_at(0b00110011, 0) )
    0
    >>> print( get_at(0b00110011, 1) )
    0
    >>> print( get_at(0b00110011, 2) )
    1
    >>> print( get_at(0b00110011, 6) )
    1 
    >>> print( get_at(0b00110011, 7) )
    1
    
  2. [5pt] List the Five Eyes countries.
    
    
    
    
    
  3. [6pts] The descriptions below are from "Security Engineering, 3rd ed". Choose the word from the box that best fits each description.
    Tempora      Prism        Muscular      Bullrun       Stuxnet
    Xkeyscore    Longhorn     Edgehill      Quantum       Duqu 
    
  4. [20pts] Let's write a simple TCP netcat client tcp_cli.py. Your program should work with nc program running as a server. See the sample run below:
    Client
    ~$ python3 tcp_cli.py 127.0.0.1 9000
    from server
    from client
    bye
    quit
    
    Server
    ~$ nc -l 9000
    from server
    from client
    bye
    
    
    Complete the code. Make sure that your code works correctly as shown in the sample run above.
    # tcp_cli.py
    import sys
    import socket
    import select
    
    ip_addr = sys.argv[1]
    port = int(sys.argv[2])
    sock = socket.socket()
    
    # add code below
    
    
    
    
    while True: socklist = [_____________, _____________] # fill in the blanks (r_sockets, w_sockets, e_sockets) = select.select(socklist, [], []) if ___________ in ____________: # fill in the blanks # add code below
    
    
    
    print(data) if sys.stdin in _____________: s = input() # add code below
    
    
    
    sock.close()