메뉴 건너뛰기

조회 수 7381 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

//파일을 읽고 쓰기 기능을 이용하여 일반문서를 읽고 암호화 하여
//저장하고 암호화된 문서를 읽고 일반 문서로 변환하는 프로그램 작성하기


 

import java.io.*;
import java.util.*;
 
class soo{
 public static void main(String[] args) throws IOException{
    System.out.println("1번과 2번중 하나를 눌러주세요 1번:파일을 읽고 암호화 합니다. " +
               " 2번:암호화 문서읽고 일반으로 변화합니다." );
    System.out.print(":");
    Scanner scan=new Scanner(System.in);
    int input=scan.nextInt();          //번호 입력할수있다.
  
    FileReader fr=null;
    FileWriter fw=null;
    int secret=3;   // 암호화&복호화 해주려는 값
   
   try{   
      if(input==1){                            //1번 입력  
      System.out.println("일반문서중 불러오고자 하는 문서명을 입력해주세요.ex)test.txt  ");
      System.out.print(":");
      String fileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력 
      fr=new FileReader(fileName);                       //불러온 파일에서 내용읽어온다.
    
     
      System.out.println("암호화된 파일을 저장할  .txt 명을 입력해주세요. ex)sos.txt");
      System.out.print(":");
      String encryptionFileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력
      fw=new FileWriter(encryptionFileName);        //암호화될 파일을 만든다.
     
      int data=0;
     
     while((data=fr.read())!=-1){
       data+=secret;   //암호화
       char ch=(char)data;  
       System.out.print(ch);         //암호화 출력    
       fw.write(data);  //암호화된 데이터를 저장한다.        
     }//while
    } //if
     
    else if(input==2){
     System.out.println("암호화 문서만 불러오세요 .ex)sos.txt  ");
     System.out.print(":");
     String fileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력 
     fr=new FileReader(fileName);              //복호화 문서 파일 내용을 읽어온다.
    
     System.out.println("복호화될 파일을 저장할  .txt 명을 입력해주세요. ex)sos.txt");
      System.out.print(":");
      String encryptionFileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력
      fw=new FileWriter(encryptionFileName);        //복호화될 파일을 만든다.
     
     int data=0;
     while((data=fr.read())!=-1){
      data-=secret;   //복호화
      char ch=(char)data;  
      System.out.print(ch);         //복호화 출력
      fw.write(data);  //복호화된 데이터를 저장한다.
     
     }//while  
      }  //else if  
   }//try{}
   catch(FileNotFoundException abc){
       System.out.println("파일을 찾을수 없습니다.");
      }
   catch(IOException ee){
  System.out.println("파일 읽을수 없다.");
   }
      finally{
    try{
        fr.close();
        fw.close();  //저장값을 반환해준다.
       }
    catch(Exception ee){}
 
   
       }//finally 닫고
      
 } //main()
 
}  //class


List of Articles
번호 제목 날짜 조회 수
151 JSP, Spring, GMail 메일발송 간단 예제 2016.09.12 32791
150 JQuery 자동완성 플러그인 JSDT설치 file 2016.09.19 8896
149 전자정부 프레임워크란? file 2016.09.19 8342
» 파일 읽고쓰는 암호화/복호화 2016.09.21 7381
147 웹브라우저(크롬) 설정하여 웹을 실행해 보자 file 2016.09.19 7202
146 회원가입 폼(form)으로 보는 Validator 구현하는 방법 file 2016.08.29 7108
145 전자정부표준프레임워크 - 설치 file 2016.09.02 6277
144 기본적인 스크립트 보안 2019.01.16 6041
143 eclipse 콘솔(로그)에 디버그(Debug) 모드에서 실행된 쿼리문을 보여주자. - 전자정부프레임워크 오라클 file 2016.08.29 5996
142 공통컴포넌트 생성하기 - 게시판 file 2016.09.19 5754
141 회원가입 양식에서 (필수/옵션)필드 추가/제거하기 file 2016.08.29 5330
140 날짜 시간 포맷 제어 자바 클래스 : JAVA DateUtils Date time file 2016.12.09 5233
139 스프링(Spring)의 Validator 기능을 사용하다가 '정의되지 않음 또는 null 참조인 'type' 속성을 가져올 수 없습니다.'라는 오류를 만났을 때 해결방법 file 2016.08.29 5164
138 System.out.println(); 이클립스에서 자동화기능 사용 file 2016.09.19 5155
137 접근 제한자 private/ protected/ public / default file 2016.10.06 5136
136 전자정부프레임워크 v2.5, v2.6 오라클 세팅하기 file 2016.09.12 5109
135 예외 만들기 2016.09.13 4961
134 MySQL에 All-in-one 설치시 webmaster로 로그인 안되는 문제 해결을 위한 2가지 수정사항 file 2016.08.29 4951
133 다양한 문자 조합을 이용한 카운팅 구하기 2016.12.09 4939
132 자바 XML 제어 라이브러리 XStream : JAVA 2016.12.09 4917
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved