-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCypher.C
48 lines (37 loc) · 964 Bytes
/
Cypher.C
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
/***********************************************************************
Cypher.C
BOOM : Bioinformatics Object Oriented Modules
Copyright (C)2012 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
***********************************************************************/
#include "Cypher.H"
#include <iostream>
using namespace BOOM;
Cypher::Cypher(const BOOM::String &key)
: key(key)
{
// ctor
}
Cypher::Cypher(const char *p,int len)
{
// ctor
for(int i=0 ; i<len ; ++i, ++p)
key+=*p;
}
BOOM::String Cypher::operator()(const BOOM::String &s)
{
int n=s.length(), k=key.length();
BOOM::String t;
for(int i=0 ; i<n ; ++i)
t+=s[i]^key[i%k];
return t;
}
BOOM::String Cypher::f(const char *p,int len)
{
int k=key.length();
BOOM::String t;
for(int i=0 ; i<len ; ++i, ++p)
t+=*p^key[i%k];
return t;
}