Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Code_analyse_frequence
- {
- static ArrayList<Character> text_lettre = new ArrayList<Character>();
- public static Scanner read = new Scanner(System.in);
- public static ArrayList<Character> antidoublon ( ArrayList<Character> newlist)
- {
- ArrayList <Character> List = new ArrayList<Character>();
- for(int i = 0 ; i < newlist.size(); i++)
- {
- Object o =newlist.get(i);
- if(!List.contains(o))
- List.add(newlist.get(i));
- }
- return List;
- }
- public static ArrayList<Character> antilettreMaj(ArrayList<Character>newlist)
- {
- for (int i =0 ; i < newlist.size(); i++) {
- if((int)newlist.get(i) >= 65 && (int)newlist.get(i) <=90 )
- {
- newlist.set(i,(char)((int)newlist.get(i)+32));
- }
- }
- return newlist;
- }
- public static void decode(ArrayList<Character>newlist , int decalage)
- {
- String text= "";
- char lettre='\0';
- int nb_charact = newlist.size();
- for(int i = 0 ; i<nb_charact ; i++)
- {
- lettre = newlist.get(i);
- if (lettre <97||lettre >122) {
- text+=(char)lettre;
- continue;
- }
- if (decalage >0)
- {
- for (int nb = 0;nb<decalage;nb++)
- {
- lettre -= 1;
- if (lettre <97)
- lettre=122;
- }
- text+=(char)lettre;
- }
- else
- {
- for (int nb = 0;nb<-decalage;nb++)
- {
- lettre += 1;
- if (lettre >122)
- lettre=97;
- }
- text+=(char)lettre;
- }
- }
- System.out.println(text);
- }
- public static void code(ArrayList<Character>newlist,int decalage)
- {
- String text= "";
- char lettre='\0';
- int nb_charact = newlist.size();
- for(int i = 0 ; i<nb_charact ; i++)
- {
- lettre = newlist.get(i);
- if (lettre <97|| lettre >122) {
- text+=(char)lettre;
- continue;
- }
- if (decalage >0)
- {
- for (int nb = 0;nb<decalage;nb++)
- {
- lettre+= 1;
- if (lettre >122)
- lettre=97;
- }
- text+=(char)lettre;
- }
- else
- {
- for (int nb = 0;nb<-decalage;nb++)
- {
- lettre -= 1;
- if (lettre <97)
- lettre=122;
- }
- text+=(char)lettre;
- }
- }
- System.out.println(text);
- }
- public static ArrayList<String> afficherTous(ArrayList<Character>newlist) {
- ArrayList<String> texteTraduit = new ArrayList<String>();
- String text= "";
- char lettre='\0';
- int nb_charact = newlist.size();
- for(int ii =0 ; ii<=25 ; ii++)
- {
- for(int i = 0 ; i<nb_charact ; i++)
- {
- lettre = newlist.get(i);
- if (lettre <90) {
- text+=(char)lettre;
- continue;
- }
- for (int nb = 0;nb<=ii;nb++)
- {
- lettre += 1;
- if (lettre >90)
- lettre=65;
- }
- text+=(char)lettre;
- }
- texteTraduit.add(text);
- text="";
- }
- return texteTraduit;
- }
- /*public static ArrayList<Character>textList(String texte)
- {
- ArrayList<Character> text_lettre = new ArrayList<Character>();
- int nb_charact = texte.length();
- for(int i = 0 ; i<nb_charact ; i++)
- text_lettre.add(i,texte.charAt(i));
- antilettreMaj(text_lettre);
- return text_lettre;
- }*/
- public static void AnalyseFreq(ArrayList<Character>newlist)
- {
- int posnbmax=0 , nbmax=0 ,nblettre=0,difference=0;// mot ayant le meme nombre de lettre ;
- char LettreE,lettrefreq;
- boolean test = false ;
- ArrayList<Character> lettre = new ArrayList<Character>();
- lettre.addAll(antidoublon(newlist));
- System.out.println(lettre+"!!!!");
- //////////////////////////////////////////////
- //cette partie du code va analiser la frequence des lettre codé
- //////////////////////////////////////////////
- for (int i =0 ;i < lettre.size() ;i++)
- {
- for (int ii =0 ;ii<newlist.size() ;ii++)
- {
- test = lettre.get(i)==newlist.get(ii);
- if(test)
- nblettre++;
- }
- if(nblettre>nbmax)
- {
- posnbmax = i;
- nbmax = nblettre;
- }
- // nb_lettre.add(i,nblettre);
- nblettre = 0;
- }
- //////////////////////////////////////////////
- //cette partie du code va s'occuper de donner la difference avec la lettre la plus commune, et redemander de tenter a chaque fois ou donner l'ordre de tous afficher
- //////////////////////////////////////////////
- System.out.println("rentrez la lettre la plus utilisé "+posnbmax);
- lettrefreq= read.nextLine().charAt(0);
- LettreE = lettre.get(posnbmax);
- System.out.println(LettreE+"mlml");
- difference = (int)LettreE-(int)lettrefreq;
- System.out.println(difference);
- decode(newlist,difference);
- }
- static void init() {
- System.out.println("rentrez votre texte a traduire");
- String texte = read.nextLine();
- int nb_charact = texte.length();
- for(int i = 0 ; i<nb_charact ; i++)
- text_lettre.add(i,texte.charAt(i));
- antilettreMaj(text_lettre);
- }
- public static void main(String[] args)
- {
- init();
- code(text_lettre,3);
- read.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement