-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrabalho_II.java
More file actions
59 lines (48 loc) · 1.57 KB
/
Trabalho_II.java
File metadata and controls
59 lines (48 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
public class Trabalho_II{
static void printPhraseDiscoded(int countTamDiscoded, String phraseCoded){
int finalIntPhrase;
char finalCharPhrase;
System.out.print("Palavra descodada: ");
for(int i = 0; i < phraseCoded.length(); i++){
if(phraseCoded.charAt(i) == 32){
System.out.print(" ");
continue;
}
finalIntPhrase = phraseCoded.charAt(i) - countTamDiscoded;
finalCharPhrase = (char)finalIntPhrase;
System.out.printf("%s", finalCharPhrase);
}
}
public static void main(String[] args){
String phraseCoded, phraseDiscoded;
int numberAsciiCoded, numberAsciiDiscoded = 0, countTamValue = 0, countValueCoded = 0;
int aux = 0, i = 0;
Scanner readPhrases = new Scanner(System.in);
System.out.print("Digite a frase codificada: ");
phraseCoded = readPhrases.nextLine();
System.out.print("Digite a frase para decodificar: ");
phraseDiscoded = readPhrases.nextLine();
for(int a = 0; a < 26; a++){
for(int j = aux; j < phraseCoded.length(); j++){
numberAsciiCoded = phraseCoded.charAt(j);
numberAsciiDiscoded = phraseDiscoded.charAt(i) + countValueCoded;
if(numberAsciiCoded == numberAsciiDiscoded){
countTamValue++;
i++;
if(countTamValue == phraseDiscoded.length()){
System.out.printf("Achei a palavra, numero de posicoes: %d\n", countValueCoded);
printPhraseDiscoded(countValueCoded, phraseCoded);
return;
}
continue;
}
countTamValue = 0;
i = 0;
}
countValueCoded++;
aux = 0;
}
System.out.print("Não achei :(");
}
}