-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteVector.cpp
114 lines (94 loc) · 2.53 KB
/
ByteVector.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "stdafx.h"
#include "ByteVector.h"
#include "IllegalVectorSizeException.h"
using namespace exceptions;
ByteVector::ByteVector(int size):size(size) {
this->word = new byte[size];
for (size_t i = 0; i < size; i++)
{
this->setByte(i, 0);
}
}
byte ByteVector::getByte(int id) const{
return word[id];
}
void ByteVector::setByte(int id, byte value)
{
word[id] = value;
}
ByteVector ByteVector::offestRight(int offsetsize) const {
ByteVector returnedvect = ByteVector(this->getLen());
for (int i = 0; i < size; i++)
{
if (offsetsize + i >= size || offsetsize + i < 0)
{
returnedvect.setByte(i, 0);
}
else
{
returnedvect.setByte(i,this->getByte(i + offsetsize));
}
}
return returnedvect;
}
ByteVector ByteVector::offestLeft(int offsetsize) const { return offestRight(-offsetsize); }
ByteVector ByteVector::operator=(const ByteVector& vect) {
if (this->getLen() != vect.getLen())throw IllegalVectorSizeException(vect.getLen(),this->getLen());
for (size_t i = 0; i < getLen(); i++)
{
setByte(i, vect.getByte(i));
}
return vect;
}
bool ByteVector::operator<(const ByteVector & other) const {
if (getLen() != other.getLen())throw IllegalVectorSizeException(getLen(), other.getLen());
for (int i = 0; i < getLen(); i++)
{
//Èíäåêñû íàäî ñ÷èòàòü ñïðàâà
int index = getLen() - i - 1;
//Åñëè õîòÿ áû îäèí èíäåêñ íå ðàâåí òî åñëè ó ýòîãî îáúåêòà 0, òî îí ìåíüøå
if (getByte(index) != other.getByte(index))return !getByte(index);
}
return false;
}
bool ByteVector::operator==(const ByteVector & other) const
{
if (getLen() != other.getLen())throw 1;
for (int i = 0; i < getLen(); i++)
{
if (getByte(i) != other.getByte(i))return false;
}
return true;
}
ByteVector ByteVector::SymmetrycSumm(const ByteVector & vect) const {
if (this->getLen() != vect.getLen())throw IllegalVectorSizeException(this->getLen(), vect.getLen());
ByteVector returnedvect = ByteVector(this->getLen());
for (size_t i = 0; i < size; i++)
{
returnedvect.setByte(i, this->getByte(i) ^ vect.getByte(i));
}
return returnedvect;
}
ByteVector::ByteVector(int vect,int size) :ByteVector(size) {
for (size_t i = 0; i < size; i++)
{
this->setByte(i,((1 << i)&vect) != 0);
}
}
//Êîíñòðóêòîð êîïèðîâàíèÿ
ByteVector::ByteVector(const ByteVector & vect) :ByteVector(vect.getLen()) {
for (size_t i = 0; i < size; i++)
{
this->setByte(i, vect.getByte(i));
}
}
ByteVector::~ByteVector() {
delete[] word;
}
ostream& operator<<(ostream& a, const ByteVector&vect) {
for (int i = vect.size - 1; i >= 0; i--)
{
a << vect.getByte(i);
}
return a;
}