Skip to content

Commit 5eebc08

Browse files
cahuizarcahuizar
authored andcommitted
Project finished
1 parent bcd853f commit 5eebc08

File tree

8 files changed

+134
-71
lines changed

8 files changed

+134
-71
lines changed

src/app/keyword-decrypt/keyword-decrypt.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
</p>
1616
<div class="center-aligned">
1717
<md-input-container>
18-
<input mdInput placeholder="Keyword">
18+
<input mdInput placeholder="Keyword" [(ngModel)]="keyword" (change) = "removeDuplicateCharacters()">
1919
</md-input-container>
2020
</div>
2121
<div class="center-aligned">
22-
<button md-raised-button class="home-button" routerLink="/encrypted">Submit</button>
22+
<button md-raised-button class="home-button" routerLink="/solution">Submit</button>
2323
</div>
2424
</md-card-content>
2525
</md-card>
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Singleton } from '../singleton.service';
3+
import { Keyword } from '../keyword';
34

45
@Component({
56
selector: 'app-keyword-decrypt',
67
templateUrl: './keyword-decrypt.component.html',
78
styleUrls: ['./keyword-decrypt.component.css']
89
})
9-
export class KeywordDecryptComponent implements OnInit {
10-
10+
export class KeywordDecryptComponent {
1111
pathText: string;
12+
keyword: string;
13+
private _keyword;
14+
private solution;
15+
private _key: Keyword;
1216

1317
constructor(private singleton: Singleton) {
14-
this.pathText = singleton.text;
15-
}
16-
17-
ngOnInit() {
18+
this.pathText = singleton.text;
19+
this.solution = [];
20+
this._key = new Keyword();
1821
}
1922

23+
removeDuplicateCharacters(): void{
24+
if(this.keyword != "" || this.keyword != undefined){
25+
this._keyword = this.keyword.split('')
26+
.filter(function(item, pos, self) {
27+
return self.indexOf(item) == pos;
28+
})
29+
.join('');
30+
this.solution = this._key.Keyword(this.pathText, this._keyword);
31+
this.singleton.solution = this.solution;
32+
}
33+
}
2034
}

src/app/keyword-encrypt/keyword-encrypt.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
</p>
1616
<div class="center-aligned">
1717
<md-input-container>
18-
<input mdInput placeholder="Keyword">
18+
<input mdInput placeholder="Keyword" [(ngModel)]="keyword" (change) = "removeDuplicateCharacters()">
1919
</md-input-container>
2020
</div>
2121
<div class="center-aligned">
22-
<button md-raised-button class="home-button" routerLink="/encrypted">Submit</button>
22+
<button md-raised-button class="home-button" routerLink="/solution">Submit</button>
2323
</div>
2424
</md-card-content>
2525
</md-card>
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Singleton } from '../singleton.service';
3+
import { Keyword } from '../keyword';
34

45
@Component({
56
selector: 'app-keyword-encrypt',
67
templateUrl: './keyword-encrypt.component.html',
78
styleUrls: ['./keyword-encrypt.component.css']
89
})
9-
export class KeywordEncryptComponent implements OnInit {
10+
export class KeywordEncryptComponent {
1011

1112
pathText: string;
13+
keyword: string;
14+
private _keyword;
15+
private solution;
16+
private _key: Keyword;
1217

1318
constructor(private singleton: Singleton) {
14-
this.pathText = singleton.text;
19+
this.pathText = singleton.text;
20+
this.solution = [];
21+
this._key = new Keyword();
1522
}
1623

17-
ngOnInit() {
18-
}
24+
removeDuplicateCharacters(): void{
25+
if(this.keyword != "" || this.keyword != undefined){
26+
this._keyword = this.keyword.split('')
27+
.filter(function(item, pos, self) {
28+
return self.indexOf(item) == pos;
29+
})
30+
.join('');
31+
this.solution = this._key.Keyword(this.pathText, this._keyword);
32+
this.singleton.solution = this.solution;
33+
}
34+
35+
}
36+
1937

2038
}

src/app/keyword.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export class Keyword {
2+
3+
Keyword(text, keyword): string {
4+
let pathText = text.split('');
5+
let solution = [];
6+
let abc = "abcdefghijklmnopqrstuvwxyz".split('');
7+
let abc2 = "abcdefghijklmnopqrstuvwxyz".split('');
8+
solution = [];
9+
for(let x = 0; x < keyword.length; x++){
10+
let index = abc.indexOf(keyword[x]);
11+
if (index > -1) {
12+
abc.splice(index, 1);
13+
}
14+
}
15+
let joinedAbc = abc.join('');
16+
let newAbc = (keyword+joinedAbc).split('');
17+
18+
for(let x = 0; x < pathText.length; x++){
19+
let index = abc2.indexOf(pathText[x]);
20+
solution[x] = newAbc[index];
21+
}
22+
return solution.join('');
23+
}
24+
25+
}

src/app/solution/solution.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2 class="solution-header">
66
</div>
77
<div class="col-xs-12">
88
<div class="div-solution center-block">
9-
<p class="solution">{{_solution}}</p>
9+
<p class="solution-text text-center">{{_solution}}</p>
1010
</div>
1111
<div class="text-center">
1212
<p>

src/app/worksheet/worksheet.component.html

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,142 @@
11
<div class="row">
22
<app-decrypt-header-buttons></app-decrypt-header-buttons>
3-
<br /> <br />
4-
<div class="col-xs-1">
3+
</div>
4+
<div class="row">
5+
<div class="padding-top"></div>
6+
<div class="col-md-1 col-xs-12">
57
<md-input-container (change)="PushValue()">
6-
<input [(ngModel)]="a" mdInput placeholder="a = ">
8+
<input [(ngModel)]="a" maxlength="1" mdInput placeholder="a = ">
79
</md-input-container>
810
</div>
9-
<div class="col-xs-1">
11+
<div class="col-md-1 col-xs-12">
1012
<md-input-container (change)="PushValue()">
11-
<input [(ngModel)]="b" mdInput placeholder="b = ">
13+
<input [(ngModel)]="b" maxlength="1" mdInput placeholder="b = ">
1214
</md-input-container>
1315
</div>
14-
<div class="col-xs-1">
16+
<div class="col-md-1 col-xs-12">
1517
<md-input-container (change)="PushValue()">
16-
<input [(ngModel)]="c" mdInput placeholder="c = ">
18+
<input [(ngModel)]="c" maxlength="1" mdInput placeholder="c = ">
1719
</md-input-container>
1820
</div>
19-
<div class="col-xs-1">
21+
<div class="col-md-1 col-xs-12">
2022
<md-input-container (change)="PushValue()">
21-
<input [(ngModel)]="d" mdInput placeholder="d = ">
23+
<input [(ngModel)]="d" maxlength="1" mdInput placeholder="d = ">
2224
</md-input-container>
2325
</div>
24-
<div class="col-xs-1">
26+
<div class="col-md-1 col-xs-12">
2527
<md-input-container (change)="PushValue()">
26-
<input [(ngModel)]="e" mdInput placeholder="e = ">
28+
<input [(ngModel)]="e" maxlength="1" mdInput placeholder="e = ">
2729
</md-input-container>
2830
</div>
29-
<div class="col-xs-1">
31+
<div class="col-md-1 col-xs-12">
3032
<md-input-container (change)="PushValue()">
31-
<input [(ngModel)]="f" mdInput placeholder="f = ">
33+
<input [(ngModel)]="f" maxlength="1" mdInput placeholder="f = ">
3234
</md-input-container>
3335
</div>
34-
<div class="col-xs-1">
36+
<div class="col-md-1 col-xs-12">
3537
<md-input-container (change)="PushValue()">
36-
<input [(ngModel)]="g" mdInput placeholder="g = ">
38+
<input [(ngModel)]="g" maxlength="1" mdInput placeholder="g = ">
3739
</md-input-container>
3840
</div>
39-
<div class="col-xs-1">
41+
<div class="col-md-1 col-xs-12">
4042
<md-input-container (change)="PushValue()">
41-
<input [(ngModel)]="h" mdInput placeholder="h = ">
43+
<input [(ngModel)]="h" maxlength="1" mdInput placeholder="h = ">
4244
</md-input-container>
4345
</div>
44-
<div class="col-xs-1">
46+
<div class="col-md-1 col-xs-12">
4547
<md-input-container (change)="PushValue()">
46-
<input [(ngModel)]="i" mdInput placeholder="i = ">
48+
<input [(ngModel)]="i" maxlength="1" mdInput placeholder="i = ">
4749
</md-input-container>
4850
</div>
49-
<div class="col-xs-1">
51+
<div class="col-md-1 col-xs-12">
5052
<md-input-container (change)="PushValue()">
51-
<input [(ngModel)]="j" mdInput placeholder="j = ">
53+
<input [(ngModel)]="j" maxlength="1" mdInput placeholder="j = ">
5254
</md-input-container>
5355
</div>
54-
<div class="col-xs-1">
56+
<div class="col-md-1 col-xs-12">
5557
<md-input-container (change)="PushValue()">
56-
<input [(ngModel)]="k" mdInput placeholder="k = ">
58+
<input [(ngModel)]="k" maxlength="1" mdInput placeholder="k = ">
5759
</md-input-container>
5860
</div>
59-
<div class="col-xs-1">
61+
<div class="col-md-1 col-xs-12">
6062
<md-input-container (change)="PushValue()">
61-
<input [(ngModel)]="l" mdInput placeholder="l = ">
63+
<input [(ngModel)]="l" maxlength="1" mdInput placeholder="l = ">
6264
</md-input-container>
6365
</div>
64-
<div class="col-xs-1">
66+
<div class="col-md-1 col-xs-12">
6567
<md-input-container (change)="PushValue()">
66-
<input [(ngModel)]="m" mdInput placeholder="m = ">
68+
<input [(ngModel)]="m" maxlength="1" mdInput placeholder="m = ">
6769
</md-input-container>
6870
</div>
69-
<div class="col-xs-1">
71+
<div class="col-md-1 col-xs-12">
7072
<md-input-container (change)="PushValue()">
71-
<input [(ngModel)]="n" mdInput placeholder="n = ">
73+
<input [(ngModel)]="n" maxlength="1" mdInput placeholder="n = ">
7274
</md-input-container>
7375
</div>
74-
<div class="col-xs-1">
76+
<div class="col-md-1 col-xs-12">
7577
<md-input-container (change)="PushValue()">
76-
<input [(ngModel)]="o" mdInput placeholder="o = ">
78+
<input [(ngModel)]="o" maxlength="1" mdInput placeholder="o = ">
7779
</md-input-container>
7880
</div>
79-
<div class="col-xs-1">
81+
<div class="col-md-1 col-xs-12">
8082
<md-input-container (change)="PushValue()">
81-
<input [(ngModel)]="p" mdInput placeholder="p = ">
83+
<input [(ngModel)]="p" maxlength="1" mdInput placeholder="p = ">
8284
</md-input-container>
8385
</div>
84-
<div class="col-xs-1">
86+
<div class="col-md-1 col-xs-12">
8587
<md-input-container (change)="PushValue()">
86-
<input [(ngModel)]="q" mdInput placeholder="q = ">
88+
<input [(ngModel)]="q" maxlength="1" mdInput placeholder="q = ">
8789
</md-input-container>
8890
</div>
89-
<div class="col-xs-1">
91+
<div class="col-md-1 col-xs-12">
9092
<md-input-container (change)="PushValue()">
91-
<input [(ngModel)]="r" mdInput placeholder="r = ">
93+
<input [(ngModel)]="r" maxlength="1" mdInput placeholder="r = ">
9294
</md-input-container>
9395
</div>
94-
<div class="col-xs-1">
96+
<div class="col-md-1 col-xs-12">
9597
<md-input-container (change)="PushValue()">
96-
<input [(ngModel)]="s" mdInput placeholder="s = ">
98+
<input [(ngModel)]="s" maxlength="1" mdInput placeholder="s = ">
9799
</md-input-container>
98100
</div>
99-
<div class="col-xs-1">
101+
<div class="col-md-1 col-xs-12">
100102
<md-input-container (change)="PushValue()">
101-
<input [(ngModel)]="t" mdInput placeholder="t = ">
103+
<input [(ngModel)]="t" maxlength="1" mdInput placeholder="t = ">
102104
</md-input-container>
103105
</div>
104-
<div class="col-xs-1">
106+
<div class="col-md-1 col-xs-12">
105107
<md-input-container (change)="PushValue()">
106-
<input [(ngModel)]="u" mdInput placeholder="u = ">
108+
<input [(ngModel)]="u" maxlength="1" mdInput placeholder="u = ">
107109
</md-input-container>
108110
</div>
109-
<div class="col-xs-1">
111+
<div class="col-md-1 col-xs-12">
110112
<md-input-container (change)="PushValue()">
111-
<input [(ngModel)]="v" mdInput placeholder="v = ">
113+
<input [(ngModel)]="v" maxlength="1" mdInput placeholder="v = ">
112114
</md-input-container>
113115
</div>
114-
<div class="col-xs-1">
116+
<div class="col-md-1 col-xs-12">
115117
<md-input-container (change)="PushValue()">
116-
<input [(ngModel)]="w" mdInput placeholder="w = ">
118+
<input [(ngModel)]="w" maxlength="1" mdInput placeholder="w = ">
117119
</md-input-container>
118120
</div>
119-
<div class="col-xs-1">
121+
<div class="col-md-1 col-xs-12">
120122
<md-input-container (change)="PushValue()">
121-
<input [(ngModel)]="x" mdInput placeholder="x = ">
123+
<input [(ngModel)]="x" maxlength="1" mdInput placeholder="x = ">
122124
</md-input-container>
123125
</div>
124-
<div class="col-xs-1">
126+
<div class="col-md-1 col-xs-12">
125127
<md-input-container (change)="PushValue()">
126-
<input [(ngModel)]="y" mdInput placeholder="y = ">
128+
<input [(ngModel)]="y" maxlength="1" mdInput placeholder="y = ">
127129
</md-input-container>
128130
</div>
129-
<div class="col-xs-1">
131+
<div class="col-md-1 col-xs-12">
130132
<md-input-container (change)="PushValue()">
131-
<input [(ngModel)]="z" mdInput placeholder="z = ">
133+
<input [(ngModel)]="z" maxlength="1" mdInput placeholder="z = ">
132134
</md-input-container>
133135
</div>
134136
</div>
135137
<div class="row">
136138
<div class="col-xs-12 col-sm-offset-1 col-sm-11">
137-
<p>
139+
<p class="cipher-question padding-top">
138140
Here is the ciphered text:
139141
</p>
140142
</div>
@@ -146,7 +148,7 @@
146148
</div>
147149
<div class="row">
148150
<div class="col-xs-12 col-sm-offset-1 col-sm-11">
149-
<p>
151+
<p class="cipher-question padding-top">
150152
Here is the solution:
151153
</p>
152154
</div>

src/styles.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ md-input-container{
262262
margin-top: 40px;
263263
}
264264

265-
p.solution{
265+
p.solution-text{
266266
font-size: 22px;
267267
text-align: center;
268268
padding: 30px;
@@ -277,6 +277,10 @@ p.solution{
277277
width: 50%;
278278
}
279279

280+
.padding-top{
281+
padding-top: 40px;
282+
}
283+
280284
.solution-github-icon{
281285
font-size:40px;
282286
}

0 commit comments

Comments
 (0)