This  is  CS50.   Harvard  College  Fall  2010  

Quiz  1  

Answer  Key     Answers  other  than  the  below  may  be  possible.       True  or  False.     0.   T  or  F   1.   T   2.   T   3.   T       DOM  DOM  DOM.     4.   Houses

Houses

  • Mather
  • other


    Bah.     5.   Any  website  that  transmits  session  cookies  in  the  clear  is  vulnerable,  not  just  Facebook.     6.   Firesheep   doesn’t   try   to   guess   session   cookies,   it   intercepts   actual   ones   by   listening   on   a   local   network  for  unencrypted  ones  from  known  sites.     7.   Facebook   does   not   use   SSL   for   other   pages,   though,   and   so   your   once-­‐encrypted   session   cookie   is   subsequently  transmitted  in  the  clear.     8.   Even   though   the   connection   between   you   and   Harvard’s   VPN   server   is   encrypted,   that   between   Harvard’s   VPN   server   and   Facebook   itself   is   not.     And   so   someone   on   the   Internet   between   Harvard  and  Facebook  could  still  hijack  your  sessions.  

0  <  6  

This  is  CS50.   Harvard  College  Fall  2010  

Frosh  IMs.     9.   http://froshims.net/register.php?name=David&gender=M&dorm=matthews     10.   function validate() {

}

if (document.getElementById("name").value == "David") { return false; } else { return true; }

    Shuttletime.     11.   bool

taken(int seat) { if (seat < 0 || seat >= SEATS) return false; return seats[seat]; }

  12.   bool

take(int seat) { if (seat < 0 || seat >= SEATS || seats[seat] == true) return false; seats[seat] = true; return true; }  

  13.   5     14.   5     15.   for (int i = 0; i < BYTES; i++)  

seats[i] = 0x00;

1  <  6  

This  is  CS50.   Harvard  College  Fall  2010  

16.   bool

taken(int seat) { if (seat < 0 || seat >= SEATS) return false; int byte = seat / 8; int mask = 1 << seat % 8; return seats[byte] & mask; }

  17.   bool take(int seat) { if (seat < 0 || seat >= SEATS) return false; int byte = seat / 8; int mask = 1 << seat % 8; if (seats[byte] & mask) return false; seats[byte] = seats[byte] | mask; return true; }

    Pointer  Fun,  still  without  Binky.     18.   The  function  prints  the  given  string,  one  character  per  line.       Numeric  Self  Defense.     19.   Plausible.     If   the   amount   of   RAM   in   laptops   has   doubled   every   18   months   (i.e.,   1.5   years)   since   1996,  then  it’s  doubled  14/1.5  ≈  9  times,  since  1996  was  14  years  ago.    David  had  4MB  then,  so  he   should  have  4MB  ×  29  =  2048MB  (i.e.,  2GB)  now,  which  is  indeed  plausible.     20.   Much  too  high.    Even  if  only  1  student  had  enrolled  in  CS50  in  1989,  21  years  have  passed,  which   would  imply  a  current  enrollment  on  the  order  of  1  ×  221  =  2,097,152.       Design  Decisions.     21.   JavaScript   should   be   used   when   you   want   to   execute   code   client-­‐side,   perhaps   to   handle   user   input,  manipulate  a  web  page’s  DOM,  or  induce  subsequent  HTTP  requests.    PHP  should  be  used   when   you   want   to   execute   code   server-­‐side,   perhaps   to   handle   a   form’s   submission,   generate   HTML,  or  write  to  a  database.    

2  <  6  

This  is  CS50.   Harvard  College  Fall  2010  

22.   You  should  pass  an  argument  by  reference  when  you  want  the  callee  to  be  able  to  change  it  or   when  the  argument  is  a  multi-­‐byte  struct  that  you’d  like  to  avoid  copying  (which  takes  time  and   space).     You   should   pass   an   argument   by   value   when   you   don’t   want   the   callee   to   be   able   to   change  it  or  when  the  time  and  space  involved  in  copying  it  is  negligible.     23.   You  should  use   gdb  when  you  want  to  debug  code,  as  by  setting  breakpoints,  stepping  through   statements,  and   examining  memory.    You  should  use   valgrind  when  you  want  to  chase  down   memory  leaks  and  invalid  pointer  dereferences.     24.   The  size  of  a  long  varies  by  architecture,  so  you  should  use  an  int64_t  when  you  want  to  ensure   that  a  variable  is  a  64-­‐bit  signed  value.     25.   You  should  use  POST  when  a  form  needs  to  submit  more  data  than  would  reasonably  fit  in  a  URL   or  when  a  form’s  data  warrants  privacy  (as  do  passwords).    You  should  use  GET  when  you  want  a   web  page  and  its  state  to  be  bookmarkable  or  emailable.       Bases  Covered.     26.   Binary   Decimal   Hexadecimal   00000000

0

0x00

00000010

2

0x02

00001010

10

0x0A

00010000

16

0x10

    Structures.     27.   1233     28.   1337       More  Structures.     29.   Even  though  searching  a  hash  table  and  searching  a  linked  list  might  be  asymptotically  equivalent,   the   fact   remains   that,   in   the   real   world,   the   former   might   very   well   take   1/26   as   much   time   as   the   latter,  a  difference  that  humans  might  certainly  notice  and  appreciate.    

3  <  6  

This  is  CS50.   Harvard  College  Fall  2010  

30.   void

print_r(node *tree) { if (tree == NULL) return; print_r(tree->left); if (tree->left) printf(","); printf("%d", tree->n); if (tree->right) printf(","); print_r(tree->right); }

    Axe  to  Valgrind.     31.   Cansu  has  likely  written  to  a  4-­‐byte  location  in  memory  that  does  not  belong  to  her  program,  as  by   indexing  beyond  the  boundary  of  an  array  of  ints.     32.   Yuhki  has  likely  allocated  40  bytes  of  memory  (as  by  allocating  10  ints)  but  failed  to  free  them.       Quickies.     33.   Steganography  is  the  science  of  hiding  information,   as  by  manipulating  the  pixels  in  an  image  in   such  a  way  that  their  colors  represents  ASCII  values.     34.   With   external   CSS   files   can   you   factor   out   properties   that   might   be   common   to   multiple   HTML   elements.     35.   Two-­‐factor   authentication   involves   challenging   users   to   present   two   forms   of   identification   in   order   to   proceed,   generally   something   they   know   (e.g.,   a   password)   and   something   they   have   (e.g.,  a  keyfob).     36.   XMLHttpRequest  objects  enable  Ajax,  a  technique  whereby  a  web  page  can  make  HTTP  requests   to  a  server  programmatically,  often  in  response  to  user  input,  in  order  to  integrate  new  content   into  its  DOM.     37.   NULL  is  a  special  pointer  that  points  to  no  object,  whereas  '\0'  is  a  char  that  generally  demarks   the  end  of  a  string.     38.   An  HTTP  cookie  is  a  key-­‐value  pair  planted  by  a  web  server  on  a  user’s  computer,  either  in  RAM  or   on  disk.     39.   The   Birthday   Problem   reveals   just   how   likely   collisions   are,   even   when   relatively   few   inputs   are   distributed  uniformly  over  a  finite  number  of  buckets.    

4  <  6  

This  is  CS50.   Harvard  College  Fall  2010  

40.   An  event  handler  is  a  function  (or  method)  that’s  called  in  response  to  some  event,  such  as  the   click  of  a  mouse.           Hello,  Katie.     41.   Version  1  is  incorrect,  as  printf  expects  a  pointer  to  a  char  as  its  second  argument,  as  implied  by   the  format  code  in  its  first  argument.    But  *s  denotes  a  char,  which  is  really  just  a  number,  and  so   *s  will  be  incorrectly  interpreted  as  an  address,  and  so  the  function  call  may  very  well  segfault  or,   at  least,  print  garbage  values.       Version  2  is  correct.       Version  3  is  incorrect.    As  in  Version  1,  printf  expects  a  pointer  to  a  char  as  its  second  argument,   but   &s   denotes   the   address   of   the   address   of   a   char,   and   so   the   function   call   may   very   well   segfault  or,  at  least,  print  garbage  values.       My  oh  my,  SQL.     42.   UPDATE clients SET cash = cash – 20 WHERE cash < 5000     43.   DELETE FROM clients WHERE username='dshen'     44.   The  hacker’s  input  will  result  in  construction  of      

SELECT id FROM clients WHERE username='$username' AND password='' OR '1' = '1'

     

which  is  equivalent  to  

 

       

         

SELECT id FROM clients

since  '1'  is  indeed  equal  to  '1'.      And  so  the  query  will  return  all  clients,  in  which  case   mysql_num_rows($result)

will  not  return  0  (assuming  the  broker  has  at  least  one  client),  at  which  point  the  first  such  client’s   id   will   be   stored   as   the   value   $_SESSION["id"].     The   result,   presumably,   is   that   the   hacker   will   effectively  be  logged  in  as  that  user,  even  without  having  known  his  or  her  password.   To  fix,  it  suffices  to  escape  all  user  input,  as  with   $username = mysql_real_escape_string($_POST["username"]); $password = mysql_real_escape_string($_POST["password"]);

   

  since  mysql_real_escape_string  will  prefix  single  quotes  with  backslashes.  

5  <  6  

Quiz 1

Bah. 5. Any website that transmits session cookies in the clear is vulnerable, not just Facebook. 6. Firesheep doesn't try to guess session cookies, it intercepts ...

100KB Sizes 3 Downloads 435 Views

Recommend Documents

Quiz 1
T or F. 1. T. 2. T. 3. T. DOM DOM DOM. 4. . . ... . Bah. 5. Any website that transmits session cookies in the clear is ...

Quiz #1
3. 9. D. 0. 10. 1. 2. Problem 1. (10pts) Find a set of rationalizable strategies. ... (10pts) Draw a payoff matrix. Answer. Player 1. Player 2. P. S. P. 3. 9. 0. 3. S. −1.

Quiz 1
Question 1 Find the components and length of pq if p = (5, 7, -1) and q = (2, 9, -2). Question 2 Find the area of the triangle whose vertices are A = (1, -1, 1),B = (0, ...

GK Exam Quiz 1.pdf
Sign in. Main menu.

QUIZ NO 1.pdf
4. Calculate. A chromatogram of a mixture of A & B provided from the. following data of HPLC, where column length was found to be 25 cm. Retention Time Peak ...

Quiz 1 2016 2017 Answers.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Quiz 1 2016 ...

Chapter 1, Section 2: Quiz - MOBILPASAR.COM
A. KEY TERMS. Match the descriptions in Column I with the terms in Column II. Write the letter of the correct answer in the blank provided. Column I. _____ 1.

Quiz 0
Complete the translation of this Scratch script to a C program below. Assume that say translates to printf; no need for newlines (\n). Rest assured that multiple translations are possible; you're welcome to introduce variables besides n and/or cross

Quiz Quiz Trade Beg Sounds.pdf
Page 1 of 13. a b. Page 1 of 13. Page 2 of 13. c d. Page 2 of 13. Page 3 of 13. e f. Page 3 of 13. Page 4 of 13. g h. Page 4 of 13. Quiz Quiz Trade Beg Sounds.pdf.

GUJARATI QUIZ
Page 1. 1. Page 2. 2. EjJ]gR[g4 S[ ` Ri EQR]i C\g]o S8? 8.c. xà«®~y. Cg_r Oj4E] .... Page 3. 3. 'EjJ]gRVr RW `i' Cg \ CrQo ^ \j4 Io? Ch` dgVg^g^. Zg]RVi csSi [rMi ...

Quiz 0
Harvard College Fall 2010. 0 < 20 ... best answers the question or completes the statement; you need not explain your answers. 0. (0 points.) ... Consider Erfan's program, below, whose lines have been numbered for the sake of discussion.

GUJARATI QUIZ
o[gV4TVi C9 ClhR T] ahV`g]o E`gRi dRi? cjTg[gHh]. C Ii ^rCC_gVo cgH`Rj4 \jhK\[ C\g4 7`o^j4 Io? 64 ]444. Ch` T\g]g[Vg J [ S_ Hg4QrTVj4 [k_Vg[ aj4 dRj4?

romeo and juliet act 1 quiz pdf
Download now. Click here if your download doesn't start automatically. Page 1 of 1. romeo and juliet act 1 quiz pdf. romeo and juliet act 1 quiz pdf. Open. Extract.

Quiz 0
invalid (e.g., garbage or NULL) pointer, and even by calling a function ... 3 < 8. Programmer Error. 25. Because the parameter, c, to capitalize is passed by value, ...

Quiz 0
Harvard College Fall 2010. 8 < 20. Quickies. Answer the questions below in no more than three sentences each. 19. (1 point.) What's pseudocode? 20. (2 points.) What's the difference between \n and \r? 21. (1 point.) Even though 232 is 4,294,967,296,

Gujarat No Vaaraso Part-1 (100 QuiZ).pdf
Gujarat No Vaaraso Part-1 (100 QuiZ).pdf. Gujarat No Vaaraso Part-1 (100 QuiZ).pdf. Open. Extract. Open with. Sign In. Main menu.

Computer GK Quiz 1-20 in Hindi PDF.pdf
(अ) वि ंडोज-7 (ब) वि ंडोज-8 (स) वि ंडोज-XP (द) MS DOS. उत्तर:- (अ). 17. ननम्न में से कोन सा System Software है? (अ) MS Word (ब) Windows 7 ...

MGT613 - Production / Operations Management Quiz # 1 Solved By ...
CBR stands for which one of the following? Select correct option: Commercial Board of Revenue. Central Board of Recycling. Central Board of Renovation.

KEY to Quiz #1 LT 5.1 REDO.pdf
Sign in. Page. 1. /. 1. Loading… Page 1 of 1. Page 1 of 1. KEY to Quiz #1 LT 5.1 REDO.pdf. KEY to Quiz #1 LT 5.1 REDO.pdf. Open. Extract. Open with. Sign In.

5.1-5.4 Quiz Review PART 1 Solutions .pdf
Page 1 of 4. Per: Part I (No Granhine Calculator). 1) Rewrite each polynomial in standard form, classifii by:Jegree (quadratic, cubic, quartic,. quantic, etc.) ...

bill-of rights-vocab-quiz-1.pdf
Page 1 of 1. The BiIl of Rights Vocabulary Quiz (1). bill-of-rights-vocab-quiz-1 What protects the basic rights of Americans? uscitizenpod.com, 2015. The First ...

Aspie-quiz - Libsyn
Aspie talent. 9.8. Above average. Neurotypical talent. 0.9. Below average. Aspie compulsion. 9.2. Above average. Neurotypical compulsion. 0.5. Below average. Aspie activity pattern. 10.0. Above average. Neurotypical social. 0.4. Below average. Aspie

Quiz 0 - CS50 CDN
In the context of files, Linux uses \n to end lines, Mac OS uses \r, and Windows ... format string's expectation of a leading %f, and so neither f nor c get filled with a ...

bill-of rights-vocab-quiz-1.pdf
powers. religion. rights. speech. the press. Whoops! There was a problem loading this page. Whoops! There was a problem previewing this document. Retrying.