Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
play-unfair
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
Harbor Registry
Model registry
Operate
Environments
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
Marcela Ribeiro de Oliveira
play-unfair
Commits
ec8e6d80
Commit
ec8e6d80
authored
7 years ago
by
Egon Nathan Bittencourt Araujo
Browse files
Options
Downloads
Patches
Plain Diff
Error with reading
Signed-off-by:
Egon Nathan Bittencourt Araujo
<
enba14@inf.ufpr.br
>
parent
53cc3969
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
playfair.cpp
+52
-12
52 additions, 12 deletions
playfair.cpp
playunfair.cpp
+7
-1
7 additions, 1 deletion
playunfair.cpp
teste3.in
+1
-0
1 addition, 0 deletions
teste3.in
with
62 additions
and
13 deletions
.gitignore
+
2
−
0
View file @
ec8e6d80
*.o
*.swp
*.swo
playunfair
*.out
This diff is collapsed.
Click to expand it.
playfair.cpp
+
52
−
12
View file @
ec8e6d80
...
...
@@ -2,12 +2,13 @@
#define _charbit(X) (1 << (X - 'a'))
#define _pos(I,J) ((I)*5 + (J)%5)
//Base idea is to use an 32-bit int as mask to detect which char
// is already on the matrix
std
::
vector
<
char
>
createKM
(
const
std
::
string
key
){
std
::
vector
<
char
>
mKey
(
25
);
std
::
string
abc
(
key
+
"abcdefghijklmnopqrstuv
x
wyz"
);
std
::
string
abc
(
key
+
"abcdefghijklmnopqrstuvw
x
yz"
);
int
mask
=
0
;
//mask with 32 bits for the 25 letter alfabet
int
si
=
0
;
...
...
@@ -30,22 +31,61 @@ std::vector< char > createKM ( const std::string key){
std
::
string
playfair
(
std
::
string
text
,
const
std
::
string
key
){
std
::
ostringstream
ret
;
std
::
vector
<
char
>
mKey
(
createKM
(
key
));
for
(
int
i
=
0
;
i
<
5
;
++
i
){
/*
for (int i=0; i<5; ++i){
for (int j=0; j<5; ++j){
std::cout << mKey[i*5 + j] << ' ';
}
std::cout << std::endl;
}
int
indexT
=
-
1
;
char
fst
=
text
[
++
indexT
];
char
snd
=
text
[
++
indexT
];
if
(
fst
==
snd
&&
snd
!=
'x'
){
snd
=
'x'
;
--
indexT
;
}
}*/
unsigned
int
indexT
=
0
;
int
repetitions
=
0
;
while
(
indexT
<
text
.
size
()
){
char
fst
=
text
[
indexT
];
char
snd
=
(
++
indexT
<
text
.
size
())
?
text
[
indexT
]
:
'x'
;
std
::
cout
<<
fst
<<
" "
<<
snd
<<
std
::
endl
;
++
indexT
;
if
(
fst
==
snd
){
if
(
snd
!=
'x'
){
snd
=
'x'
;
}
else
{
snd
=
'q'
;
}
--
indexT
;
++
repetitions
;
}
int
iFst
,
iSnd
;
int
iFst
,
iSnd
;
for
(
int
i
=
0
;
i
<
25
;
++
i
){
if
(
mKey
[
i
]
==
fst
||
((
fst
==
'i'
||
fst
==
'j'
)
&&
(
mKey
[
i
]
==
'i'
||
mKey
[
i
]
==
'j'
))){
iFst
=
i
;
}
if
(
mKey
[
i
]
==
snd
||
((
snd
==
'i'
||
snd
==
'j'
)
&&
(
mKey
[
i
]
==
'i'
||
mKey
[
i
]
==
'j'
))){
iSnd
=
i
;
}
}
char
retfst
,
retsnd
;
if
(
iFst
/
5
==
iSnd
/
5
){
retfst
=
mKey
[
_pos
(
iFst
/
5
,
(
iFst
+
1
))];
retsnd
=
mKey
[
_pos
(
iSnd
/
5
,(
iSnd
+
1
))];
}
else
if
(
iFst
%
5
==
iSnd
%
5
){
std
::
cout
<<
iFst
<<
" "
<<
iFst
/
5
<<
" "
<<
((
iFst
/
5
)
+
1
)
%
5
<<
std
::
endl
;
retfst
=
mKey
[
_pos
(
((
iFst
/
5
)
+
1
)
%
5
,
(
iFst
))];
std
::
cout
<<
retfst
<<
" "
<<
_pos
(
((
iFst
/
5
)
+
1
)
%
5
,
(
iFst
))
<<
std
::
endl
;
retsnd
=
mKey
[
_pos
(
((
iSnd
/
5
)
+
1
)
%
5
,
(
iSnd
))];
}
else
{
retfst
=
mKey
[
_pos
(
iFst
/
5
,
iSnd
)];
retsnd
=
mKey
[
_pos
(
iSnd
/
5
,
iFst
)];
}
ret
<<
retfst
<<
retsnd
;
}
std
::
cout
<<
ret
.
str
()
<<
std
::
endl
;
//TODO:change
return
text
;
return
ret
.
str
()
;
}
This diff is collapsed.
Click to expand it.
playunfair.cpp
+
7
−
1
View file @
ec8e6d80
...
...
@@ -13,11 +13,13 @@ int main(int argc, char *argv[]){
}
std
::
fstream
input
,
output
;
char
*
inputName
,
*
outputName
;
std
::
string
aux
,
key
=
"cachorro"
,
crip
;
//a key vai vir do dicionario futuramente
std
::
string
aux
=
""
,
key
=
"cachorro"
,
crip
;
//a key vai vir do dicionario futuramente
std
::
ostringstream
text
;
inputName
=
argv
[
1
];
outputName
=
argv
[
2
];
//TODO: ELE TA LENDO CAGADO JA, olha o fim desse comment
input
.
open
(
inputName
,
std
::
ifstream
::
in
);
if
(
!
input
.
good
()){
std
::
cout
<<
"Nao foi possivel abrir o arquivo de entrada"
<<
std
::
endl
;
...
...
@@ -27,9 +29,13 @@ int main(int argc, char *argv[]){
while
(
std
::
getline
(
input
,
aux
))
text
<<
aux
;
std
::
cout
<<
text
.
str
()[
0
]
<<
std
::
endl
;
//TODO: ERRO ACABA AQUI, veja o resultado disso aqui^ com o teste3.in
return
0
;
crip
=
text
.
str
();
parser
(
crip
);
std
::
cout
<<
crip
<<
std
::
endl
;
crip
=
playfair
(
crip
,
key
);
std
::
cout
<<
crip
<<
std
::
endl
;
return
0
;
}
This diff is collapsed.
Click to expand it.
teste3.in
0 → 100644
+
1
−
0
View file @
ec8e6d80
youshallnot pas
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