Method: EncryptDecrypt.interactive_terminal
- Defined in:
- lib/accu-encrypt.rb
.interactive_terminal ⇒ Object
Opens an interactive terminal session.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/accu-encrypt.rb', line 430 def self.interactive_terminal() print "Welcome to interactive encode/decode. " selection = "" @@mode = :normal verbose = true while selection != "q" do puts "What would you like to do? |E D I M N Q|" selection = gets.downcase selection.slice!(-1) if selection == "e" then file = "" ready = false while not ready do file = FileLibrary.select_file if verbose then puts "---------\nWARNING!!!!!\n---------\nEncoding a file could un-retrievably destroy the contents of this file. Are you sure you would like to use this file? |Y N Q|" selection2 = gets.downcase selection2.slice!(-1) while (selection2 != "y" and selection2 != "n" and selection2 != "q") do puts "Incorrect choice: |" + selection2 + "|\nAre you sure you would like to use this file? |Y N Q|" selection2 = gets.downcase selection2.slice!(-1) end if selection2 == "q" then ready = true file = "" elsif selection2 == "y" then ready = true end else ready = true end end if File.exists? file then password = EncryptDecrypt.get_password if verbose then puts "Finally, are you sure you would like to encrypt this file using this password? |Y N|" selection2 = gets.downcase selection2.slice!(-1) if selection2 == "y" then self.encrypt_file(file,password,@@mode) puts "Successfully encrypted file." end else self.encrypt_file(file,password,@@mode) puts "Successfully encrypted file." end end elsif selection == "d" then file = "" ready = false while not ready do file = FileLibrary.select_file if verbose then puts "---------\nWARNING!!!!!\n---------\nDecoding a file which has not been encrypted will destroy the contents.\nDecoding a file with the incorrect password will likely also destroy the file.\n---------\nAre you sure you would like to use this file? |Y N Q|" selection2 = gets.downcase selection2.slice!(-1) while (selection2 != "y" and selection2 != "n" and selection2 != "q") do puts "Incorrect choice: |" + selection2 + "|\nAre you sure you would like to use this file? |Y N Q|" selection2 = gets.downcase selection2.slice!(-1) end if selection2 == "q" then ready = true file = "" elsif selection2 == "y" then ready = true end else ready = true end end if File.exists? file then password = EncryptDecrypt.get_password if verbose then puts "Finally, are you sure you would like to decrypt this file using this password? |Y N|" selection2 = gets.downcase selection2.slice!(-1) if selection2 == "y" then self.decrypt_file(file,password,@@mode) puts "Successfully decrypted file." end else self.decrypt_file(file,password,@@mode) puts "Successfully decrypted file." end end elsif selection == "i" then puts EncryptDecrypt.interactive_help elsif selection == "m" then puts "Select mode: Double - D Normal - N Verbose - V Unverbose - U" selection2 = "" selection2 = gets.downcase selection2.slice!(-1) while (selection2 != "d" and selection2 != "n" and selection2 != "v" and selection2 != "u") do puts "Invalid: |" + selection2 + "|" selection2 = gets.downcase selection2.slice!(-1) end if selection2 == "d" then @@mode = :double elsif selection2 == "v" then verbose = true elsif selection2 == "u" then verbose = false else @@mode = :normal end elsif selection == "n" then puts "Port number: " selection2 = "" selection2 = gets.downcase selection2.slice!(-1) while (selection2.to_i == 0 or selection2.to_i == nil) do puts "Invalid: |" + selection2 + "|" selection2 = gets.downcase selection2.slice!(-1) end port = selection2.to_i puts "Would you like to open a client or a server? |C S|" selection2 = "" selection2 = gets.downcase selection2.slice!(-1) while (selection2 != "c" and selection2 != "s") do puts "Invalid: |" + selection2 + "|" selection2 = gets.downcase selection2.slice!(-1) end if selection2 == "c" then puts "IP: " ip = "" ip = gets.downcase ip.slice!(-1) begin server = TCPSocket.open( ip, port ) EncryptedClient.new( server ) server.close rescue puts "ERROR\nConnection probably refused." end else server = TCPServer.open port EncryptedServer.new( server.accept ) server.close end puts "Returning to normal encryption tasks." elsif selection != "q" then puts "Incorrect selection: |" + selection + "|" end end end |