Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Criptografia T2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mgh16
Criptografia T2
Commits
d959617b
Commit
d959617b
authored
2 years ago
by
mgh16
Browse files
Options
Downloads
Patches
Plain Diff
talvez os dois funcionando
parent
b55aaf19
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cifra_railOnSteroids.c
+2
-1
2 additions, 1 deletion
cifra_railOnSteroids.c
decifra_railOnSteroids.c
+106
-0
106 additions, 0 deletions
decifra_railOnSteroids.c
with
108 additions
and
1 deletion
cifra_railOnSteroids.c
+
2
−
1
View file @
d959617b
...
...
@@ -49,7 +49,8 @@ int main(){
for
(
int
itr
=
0
;
itr
<
num_chaves
;
itr
++
){
printf
(
"itr %d de %d
\n
"
,
itr
,
num_chaves
);
int
mod_text_pela_chave
=
(
tamanho_texto
)
%
chaves_parciais
[
itr
];
int
caracteres_p_completar
=
chaves_parciais
[
itr
]
-
mod_text_pela_chave
;
int
caracteres_p_completar
=
(
mod_text_pela_chave
>
0
)
?
chaves_parciais
[
itr
]
-
mod_text_pela_chave
:
0
;
printf
(
"completando %d caracteres, texto tinha %d
\n
"
,
caracteres_p_completar
,
tamanho_texto
);
...
...
This diff is collapsed.
Click to expand it.
decifra_railOnSteroids.c
0 → 100644
+
106
−
0
View file @
d959617b
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<ctype.h>
#define TAM_MAX_TEXTO 1000000
int
main
(){
char
texto_claro
[
TAM_MAX_TEXTO
];
char
texto_cifrado
[
TAM_MAX_TEXTO
]
;
long
int
chave
;
puts
(
"digite o texto a ser cifrado"
);
fgets
(
texto_claro
,
sizeof
texto_claro
,
stdin
);
puts
(
"digite a chave (inteiros) para cifrar o texto"
);
scanf
(
"%ld"
,
&
chave
);
int
num_chaves
=
0
;
long
int
aux
=
chave
;
while
(
aux
!=
0
){
num_chaves
++
;
aux
=
aux
/
10
;
}
int
*
chaves_parciais
=
malloc
(
sizeof
(
int
)
*
num_chaves
);
for
(
int
i
=
0
;
i
<
num_chaves
;
i
++
){
chaves_parciais
[
i
]
=
chave
%
10
;
chave
=
chave
/
10
;
}
int
tamanho_texto
=
strlen
(
texto_claro
)
-
1
;
for
(
int
i
=
0
;
i
<
tamanho_texto
;
i
++
){
texto_claro
[
i
]
=
toupper
(
texto_claro
[
i
]);
}
for
(
int
i
=
0
;
i
<
tamanho_texto
;
i
++
){
texto_cifrado
[
i
]
=
texto_claro
[
i
];
}
for
(
int
itr
=
0
;
itr
<
num_chaves
;
itr
++
){
printf
(
"itr %d de %d
\n
"
,
itr
,
num_chaves
);
int
mod_text_pela_chave
=
(
tamanho_texto
)
%
chaves_parciais
[
itr
];
int
caracteres_p_completar
=
(
mod_text_pela_chave
>
0
)
?
chaves_parciais
[
itr
]
-
mod_text_pela_chave
:
0
;
printf
(
"completando %d caracteres, texto tinha %d
\n
"
,
caracteres_p_completar
,
tamanho_texto
);
for
(
int
i
=
0
;
i
<
caracteres_p_completar
;
i
++
){
texto_cifrado
[
tamanho_texto
+
i
]
=
'X'
;
}
tamanho_texto
+=
caracteres_p_completar
;
int
caracteresporlinha
=
(
tamanho_texto
+
mod_text_pela_chave
)
/
chaves_parciais
[
itr
];
printf
(
"caracteres por linha = %d
\n
"
,
caracteresporlinha
);
char
matrizTransposicao
[
10
][
caracteresporlinha
];
int
caracter
=
0
;
for
(
int
i
=
0
;
i
<
chaves_parciais
[
itr
];
i
++
){
for
(
int
j
=
0
;
j
<
caracteresporlinha
;
j
++
){
printf
(
"linha %d coluna %d caracter %c
\n
"
,
i
,
j
,
texto_cifrado
[
caracter
]);
matrizTransposicao
[
i
][
j
]
=
texto_cifrado
[
caracter
];
caracter
++
;
}
}
caracter
=
0
;
for
(
int
j
=
0
;
j
<
caracteresporlinha
;
j
++
){
for
(
int
i
=
0
;
i
<
chaves_parciais
[
itr
];
i
++
){
if
(
caracter
<
tamanho_texto
){
printf
(
"%c
\n
"
,
matrizTransposicao
[
i
][
j
]);
texto_cifrado
[
caracter
]
=
matrizTransposicao
[
i
][
j
];
}
caracter
++
;
}
}
}
puts
(
"=== texto decifrado eh ==="
);
for
(
int
i
=
0
;
i
<
tamanho_texto
;
i
++
){
printf
(
"%c"
,
texto_cifrado
[
i
]);
}
puts
(
""
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment