本文整理汇总了C++中ROTATE函数的典型用法代码示例。如果您正苦于以下问题:C++ ROTATE函数的具体用法?C++ ROTATE怎么用?C++ ROTATE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ROTATE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: indexToDetectorOffsetX
CVector3D CConeProjectionGeometry3D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const
{
float32 fSrcX = -m_fOriginSourceDistance;
float32 fSrcY = 0.0f;
float32 fSrcZ = 0.0f;
float32 fDetX = m_fOriginDetectorDistance;
float32 fDetY = 0.0f;
float32 fDetZ = 0.0f;
fDetY += indexToDetectorOffsetX(_iDetectorIndex);
fDetZ += indexToDetectorOffsetY(_iDetectorIndex);
float32 angle = m_pfProjectionAngles[_iProjectionIndex];
#define ROTATE(name,alpha) do { float32 tX = f##name##X * cos(alpha) - f##name##Y * sin(alpha); f##name##Y = f##name##X * sin(alpha) + f##name##Y * cos(alpha); f##name##X = tX; } while(0)
ROTATE(Src, angle);
ROTATE(Det, angle);
#undef ROTATE
CVector3D ret(fDetX - fSrcX, fDetY - fSrcY, fDetZ - fDetZ);
return ret;
}
开发者ID:eureka3,项目名称:astra-toolbox,代码行数:25,代码来源:ConeProjectionGeometry3D.cpp
示例2: chacha_round
static inline void chacha_round(uint32_t x[16], int a, int b, int c, int d)
{
x[a] += x[b]; x[d] ^= x[a]; ROTATE(x[d], 16);
x[c] += x[d]; x[b] ^= x[c]; ROTATE(x[b], 12);
x[a] += x[b]; x[d] ^= x[a]; ROTATE(x[d], 8);
x[c] += x[d]; x[b] ^= x[c]; ROTATE(x[b], 7);
}
开发者ID:reubenhwk,项目名称:secure,代码行数:7,代码来源:chacha.c
示例3: sha1_process_block
void sha1_process_block(sha1_ctx_t *p, const byte *block)
{
static uint32 K[4] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 };
uint32 a, b, c, d, e, f, k, temp;
a = p->h[0];
b = p->h[1];
c = p->h[2];
d = p->h[3];
e = p->h[4];
uint32 w[80];
int i;
for (i = 0; i < 16; i++) {
w[i] = block[i*4+0] << 24;
w[i] |= block[i*4+1] << 16;
w[i] |= block[i*4+2] << 8;
w[i] |= block[i*4+3];
}
for (i = 16; i < 80; i++)
w[i] = ROTATE((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
for (i = 0; i < 80; i++) {
if (0 <= i && i < 20) {
f = (b & c) ^ ((~b) & d);
k = K[0];
} else if (20 <= i && i < 40) {
f = b ^ c ^ d;
k = K[1];
} else if (40 <= i && i < 60) {
f = (b & c) ^ (b & d) ^ (c & d);
k = K[2];
} else if (60 <= i && i < 80) {
f = b ^ c ^ d;
k = K[3];
}
temp = ROTATE(a, 5) + f + e + k + w[i];
e = d;
d = c;
c = ROTATE(b, 30);
b = a;
a = temp;
}
p->h[0] += a;
p->h[1] += b;
p->h[2] += c;
p->h[3] += d;
p->h[4] += e;
}
开发者ID:vni,项目名称:programming,代码行数:54,代码来源:sha1.c
示例4: md5_digest
void md5_digest (md5_t* self) {
uint32_t data[16], a, b, c, d;
a = self->rawhash[0];
b = self->rawhash[1];
c = self->rawhash[2];
d = self->rawhash[3];
for (int i = 0, j = 0; i < 16; ++i, j+=4)
data[i] = (self->buffer[j] ) + (self->buffer[j + 1] << 8) +
(self->buffer[j + 2] << 16) + (self->buffer[j + 3] << 24);
for (int i = 0; i < 64; ++i) {
uint32_t func, temp;
if (i < 16) func = F(b,c,d);
else if (i < 32) func = G(b,c,d);
else if (i < 48) func = H(b,c,d);
else if (i < 64) func = I(b,c,d);
temp = d;
d = c;
c = b;
b = b + ROTATE(a + func + data[M[i]] + K[i], S[i]);
a = temp;
}
self->rawhash[0] += a;
self->rawhash[1] += b;
self->rawhash[2] += c;
self->rawhash[3] += d;
}
开发者ID:rossmacarthur,项目名称:md5-brute-forcer,代码行数:34,代码来源:md5.c
示例5: TERNARY
void TERNARY(stack& s) {
NULLARY(s);
ROTATE(s);
POP(s);
POP(s);
SWAP(s);
POP(s);
}
开发者ID:basictalk,项目名称:joy,代码行数:8,代码来源:int_combinator.cpp
示例6: RotateBuffer
/* ---------------------------------------------------------------------------
* rotates the contents of the pastebuffer
*/
void
RotateBuffer (BufferType *Buffer, BYTE Number)
{
/* rotate vias */
VIA_LOOP (Buffer->Data);
{
r_delete_entry (Buffer->Data->via_tree, (BoxType *)via);
ROTATE_VIA_LOWLEVEL (via, Buffer->X, Buffer->Y, Number);
SetPinBoundingBox (via);
r_insert_entry (Buffer->Data->via_tree, (BoxType *)via, 0);
}
END_LOOP;
/* elements */
ELEMENT_LOOP (Buffer->Data);
{
RotateElementLowLevel (Buffer->Data, element, Buffer->X, Buffer->Y,
Number);
}
END_LOOP;
/* all layer related objects */
ALLLINE_LOOP (Buffer->Data);
{
r_delete_entry (layer->line_tree, (BoxType *)line);
RotateLineLowLevel (line, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->line_tree, (BoxType *)line, 0);
}
ENDALL_LOOP;
ALLARC_LOOP (Buffer->Data);
{
r_delete_entry (layer->arc_tree, (BoxType *)arc);
RotateArcLowLevel (arc, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->arc_tree, (BoxType *)arc, 0);
}
ENDALL_LOOP;
ALLTEXT_LOOP (Buffer->Data);
{
r_delete_entry (layer->text_tree, (BoxType *)text);
RotateTextLowLevel (text, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->text_tree, (BoxType *)text, 0);
}
ENDALL_LOOP;
ALLPOLYGON_LOOP (Buffer->Data);
{
r_delete_entry (layer->polygon_tree, (BoxType *)polygon);
RotatePolygonLowLevel (polygon, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->polygon_tree, (BoxType *)polygon, 0);
}
ENDALL_LOOP;
/* finally the origin and the bounding box */
ROTATE (Buffer->X, Buffer->Y, Buffer->X, Buffer->Y, Number);
RotateBoxLowLevel (&Buffer->BoundingBox, Buffer->X, Buffer->Y, Number);
SetCrosshairRangeToBuffer ();
}
开发者ID:bgamari,项目名称:geda-pcb,代码行数:59,代码来源:buffer.c
示例7: TRANSLATE
void
SbMatrix::setTransform(const SbVec3f &translation,
const SbRotation &rotation,
const SbVec3f &scaleFactor,
const SbRotation &scaleOrientation,
const SbVec3f ¢er)
{
#define TRANSLATE(vec) m.setTranslate(vec), multLeft(m)
#define ROTATE(rot) rot.getValue(m), multLeft(m)
SbMatrix m;
makeIdentity();
if (translation != SbVec3f(0,0,0))
TRANSLATE(translation);
if (center != SbVec3f(0,0,0))
TRANSLATE(center);
if (rotation != SbRotation(0,0,0,1))
ROTATE(rotation);
if (scaleFactor != SbVec3f(1,1,1)) {
SbRotation so = scaleOrientation;
if (so != SbRotation(0,0,0,1))
ROTATE(so);
m.setScale(scaleFactor);
multLeft(m);
if (so != SbRotation(0,0,0,1)) {
so.invert();
ROTATE(so);
}
}
if (center != SbVec3f(0,0,0))
TRANSLATE(-center);
#undef TRANSLATE
#undef ROTATE
}
开发者ID:OpenXIP,项目名称:xip-libraries,代码行数:42,代码来源:SbMatrix.cpp
示例8: hash
int hash(const char * word)
{
int i;
long hv = 0;
for (i=0; i < 4 && *word != 0; i++)
hv = (hv << 8) | (*word++);
while (*word != 0) {
ROTATE(hv,ROTATE_LEN);
hv ^= (*word++);
}
return (unsigned long) hv % tablesize;
}
开发者ID:ZacWalk,项目名称:ImageWalker,代码行数:12,代码来源:munch.c
示例9: printit
static void
printit(const char *arg)
{
int ch, rot;
if ((rot = atoi(arg)) < 0)
errx(1, "bad rotation value");
while ((ch = getchar()) != EOF)
putchar(ROTATE(ch, rot));
exit(0);
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:12,代码来源:caesar.c
示例10: ff_dct_calc_c
static void ff_dct_calc_c(DCTContext *s, FFTSample *data)
{
int n = 1<<s->nbits;
int i;
#define ROTATE(i,n) (-M_PI*((n)-0.5f)*(i)/(n))
if (s->inverse) {
for(i=0; i < n; i++) {
s->data[i].re = (float) (2 * data[i] * cos(ROTATE(i,n)));
s->data[i].im = (float) (2 * data[i] * sin(ROTATE(i,n)));
}
s->data[n].re = 0;
s->data[n].im = 0;
for(i=0; i<n-1; i++) {
s->data[n+i+1].re = (float) (-2 * data[n - (i+1)] * cos(ROTATE(n+i+1,n)));
s->data[n+i+1].im = (float) (-2 * data[n - (i+1)] * sin(ROTATE(n+i+1,n)));
}
}else{
for(i=0; i < n; i++) {
s->data[i].re = data[n - (i+1)];
s->data[i].im = 0;
s->data[n+i].re = data[i];
s->data[n+i].im = 0;
}
}
ff_fft_permute(&s->fft, s->data);
ff_fft_calc(&s->fft, s->data);
if (s->inverse) {
for(i=0; i < n; i++)
data[i] = s->data[n-(i+1)].re / (2 * n);
}else {
for(i=0; i < n; i++)
data[i] = (float) (s->data[i].re / (2 * cos(ROTATE(i,n))));
}
#undef ROTATE
}
开发者ID:AlanWasTaken,项目名称:gemrb,代码行数:38,代码来源:dct.cpp
示例11: RotateMarkedItems
/** Rotate marked items, refer to a rotation point at position offset
* Note: because this function is used in global transform,
* if force_all is true, all items will be rotated
*/
void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all )
{
#define ROTATE( z ) RotatePoint( (&z), offset, 900 )
if( module == NULL )
return;
if( module->Reference().IsSelected() || force_all )
module->Reference().Rotate( offset, 900 );
if( module->Value().IsSelected() || force_all )
module->Value().Rotate( offset, 900 );
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
{
if( !pad->IsSelected() && !force_all )
continue;
wxPoint pos = pad->GetPos0();
ROTATE( pos );
pad->SetPos0( pos );
pad->SetOrientation( pad->GetOrientation() + 900 );
pad->SetDrawCoord();
}
for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
{
if( !item->IsSelected() && !force_all )
continue;
switch( item->Type() )
{
case PCB_MODULE_EDGE_T:
((EDGE_MODULE*) item)->Rotate( offset, 900 );
break;
case PCB_MODULE_TEXT_T:
static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
break;
default:
break;
}
}
ClearMarkItems( module );
}
开发者ID:RocFan,项目名称:kicad-source-mirror,代码行数:52,代码来源:block_module_editor.cpp
示例12: jacobi
int jacobi(double** a, double* d, double** v)
{
int nrot = 0;
const unsigned int nmax = 100, n = 3;
double b[nmax], z[nmax], tresh,sm,g,h,t,theta,c,s,tau;
int i,j,ip,iq;
for(ip=1;ip<=n;ip++) {
for(iq=1;iq<=n;iq++) v[ip][iq] = 0.0f;
v[ip][ip] = 1.0f;
}
for(ip=1;ip<=n;ip++) {
b[ip] = d[ip] = a[ip][ip];
z[ip] = 0.0f;
}
for(i=1;i<=50;i++) {
sm = 0.0f;
for(ip=1;ip<=n-1;ip++) {
for(iq=ip+1;iq<=n;iq++)
sm += fabs(a[ip][iq]);
}
if(sm == 0.0f)
return(0);
if(i < 4) {
tresh = 0.2f * sm / ( n*n );
}
else {
tresh = 0.0f;
}
for(ip=1;ip<=n-1;ip++) {
for(iq=ip+1;iq<=n;iq++) {
g = 100.0f*fabs(a[ip][iq]);
if( (i > 4) && (double)(fabs(d[ip])+g) == (double)fabs(d[ip]) && (double)(fabs(d[iq])+g) == (double)fabs(d[iq]))
a[ip][iq] = 0.0f;
else if( fabs(a[ip][iq]) > tresh ) {
h = d[iq] - d[ip];
if( (fabs(h)+g) == fabs(h) )
t = a[ip][iq] / h;
else {
theta = 0.5f * h / (a[ip][iq]);
t = 1.0f / (fabs(theta) + sqrt(1.0f + theta*theta));
if(theta < 0.0f) t *= -1.0f;
}
c = 1.0f / sqrt(1.0f + t*t);
s = t * c;
tau = s / (1.0f + c);
h = t * a[ip][iq];
z[ip] -= h;
z[iq] += h;
d[ip] -= h;
d[iq] += h;
a[ip][iq] = 0.0f;
for(j=1;j<=ip-1;j++) {
ROTATE(a,j,ip,j,iq);
}
for(j=ip+1;j<=iq-1;j++) {
ROTATE(a,ip,j,j,iq);
}
for(j=iq+1;j<=n;j++) {
ROTATE(a,ip,j,iq,j);
}
for(j=1;j<=n;j++) {
ROTATE(v,j,ip,j,iq);
}
++nrot;
}
}
}
for(ip=1;ip<=n;ip++) {
b[ip] += z[ip];
d[ip] = b[ip];
z[ip] = 0.0f;
}
}
assert(i<50);
return 1;
}
开发者ID:bmi-forum,项目名称:bmi-pyre,代码行数:85,代码来源:Constitutive.c
示例13: jacobi
void jacobi(Matrix<double> &a, int n, double* d, Matrix<double> &v, int nrot)
{
int i, j, iq, ip;
double tresh, theta, tau, t, sm, s, h, g, c;
double* b = new double[n + 1];
double* z = new double[n + 1];
for (ip = 1; ip <= n; ip++)
{
ZeroMemory(v[ip], sizeof(double) * (n + 1));
v[ip][ip]=1.0;
}
for (ip = 1; ip <= n; ip++)
{
b[ip] = d[ip] = a[ip][ip];
z[ip] = 0.0;
}
nrot = 0;
for (i = 1; i <= 50; i++)
{
sm = 0.0;
for (ip = 1; ip <= n - 1; ip++)
{
for (iq = ip + 1; iq <= n; iq++)
{
sm += fabs(a[ip][iq]);
}
}
if (sm == 0.0)
{
delete[] b;
delete[] z;
return;
}
if (i < 4)
{
tresh = 0.2 * sm / (n * n);
}
else
{
tresh = 0.0;
}
for (ip = 1;ip <= n - 1; ip++)
{
for (iq = ip + 1; iq <= n; iq++)
{
g = 100.0 * fabs(a[ip][iq]);
if ((i > 4) && (fabs(d[ip]) + g == fabs(d[ip])) && (fabs(d[iq]) + g == fabs(d[iq])))
{
a[ip][iq] = 0.0;
}
else if (fabs(a[ip][iq]) > tresh)
{
h = d[iq] - d[ip];
if (fabs(h) + g == fabs(h))
{
t = (a[ip][iq]) / h;
}
else
{
theta = 0.5 * h / (a[ip][iq]);
t = 1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
if (theta < 0.0)
{
t = -t;
}
}
c = 1.0 / sqrt(1 + t * t);
s = t * c;
tau = s / (1.0 + c);
h = t * a[ip][iq];
z[ip] -= h;
z[iq] += h;
d[ip] -= h;
d[iq] += h;
a[ip][iq]=0.0;
for (j = 1;j <= ip - 1; j++)
{
ROTATE(a, j, ip, j, iq, tau, s);
}
for (j = ip + 1; j <= iq - 1; j++)
{
ROTATE(a, ip, j, j, iq, tau, s);
}
for (j = iq + 1; j <= n; j++)
{
ROTATE(a, ip, j, iq, j, tau, s);
//.........这里部分代码省略.........
开发者ID:sanyaade-g2g-repos,项目名称:quickdiagram,代码行数:101,代码来源:EllipseFit.cpp
示例14: jacobi_decompose
//Algorithm from the Wikipedia entry on Jacobi decomposition
void jacobi_decompose(double cov_matrix[][NUM_PARAMS], double *eigenvalues, double orth_matrix[][NUM_PARAMS]) {
int i,j,k,l;
int max_col[NUM_PARAMS];
int changed[NUM_PARAMS]; //To keep track of eigenvalues changing
int n = NUM_PARAMS;
int max_row;
int state = 0;
double max, c, s, t, u, a;
int count = 0;
//Set up the maximum value cache
for (i=0; i<n; i++) {
max=0;
max_col[i] = i+1;
for (j=i+1; j<n; j++) {
if (fabs(cov_matrix[i][j])>max) {
max_col[i] = j;
max = fabs(cov_matrix[i][j]);
}
}
}
//Set up the orthogonal matrix as the identity:
for (i=0; i<n; i++)
for (j=0; j<n; j++)
orth_matrix[i][j] = (i==j) ? 1 : 0;
//Copy the diagonal values to the eigenvalue array:
for (i=0; i<n; i++) {
eigenvalues[i] = cov_matrix[i][i];
changed[i] = 1;
for (j=0; j<n; j++)
if (j!=i && cov_matrix[i][j]) break;
if (j==n) {
state--;
changed[i] = 0;
}
}
//Sweep time: iterate until the eigenvalues stop changing.
state += n;
while (state) {
count++;
//Find the largest nonzero element in the matrix:
max = fabs(cov_matrix[0][max_col[0]]);
max_row = 0;
for (i=1; i<n-1; i++) {
if (fabs(cov_matrix[i][max_col[i]])>max) {
max = fabs(cov_matrix[i][max_col[i]]);
max_row = i;
}
}
k = max_row; l = max_col[k];
max = cov_matrix[k][l];
//Calculate the Jacobi rotation matrix
//Tan 2phi = 2S_kl / (S_kk - S_ll)
a = (eigenvalues[l] - eigenvalues[k]) * 0.5;
t = fabsl(a) + sqrtl(max*max + a*a);
s = sqrtl(max*max + t*t);
c = t/s;
s = max/s;
t = max*max / t;
if (a<0) {
s = -s; t = -t;
}
//Update eigenvalues
#define UPDATE(x,y) \
a = eigenvalues[x]; \
eigenvalues[x] += y; \
if (changed[x] && (eigenvalues[x]==a)) { /*Eigenvalue didn't change*/ \
changed[x]=0; \
state--; \
} else if (!changed[x] && (eigenvalues[x]!=a)) { /*Egval did change*/ \
changed[x] = 1; \
state++; \
}
UPDATE(k, -t);
UPDATE(l, t);
//Update covariance matrix:
cov_matrix[k][l] = 0;
#define ROTATE(m,w,x,y,z,r) /*Perform a Jacobi rotation*/ \
t = m[w][x]; u = m[y][z]; \
m[w][x] = t*c - s*u; \
m[y][z] = s*t + c*u; \
if (r) { \
if (fabs(m[w][x])>fabs(m[w][max_col[w]])) \
max_col[w] = x; \
if (fabs(m[y][z])>fabs(m[y][max_col[y]])) \
max_col[y] = z; \
}
for (i=0; i<k; i++) { ROTATE(cov_matrix,i,k,i,l,1); }
for (i=k+1; i<l; i++) { ROTATE(cov_matrix,k,i,i,l,1); }
//.........这里部分代码省略.........
开发者ID:markushaider,项目名称:generate_tree,代码行数:101,代码来源:jacobi.c
示例15: DES_encrypt1
void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
{
register DES_LONG l, r, t, u;
#ifdef DES_PTR
register const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
#endif
#ifndef DES_UNROLL
register int i;
#endif
register DES_LONG *s;
r = data[0];
l = data[1];
IP(r, l);
/*
* Things have been modified so that the initial rotate is done outside
* the loop. This required the DES_SPtrans values in sp.h to be rotated
* 1 bit to the right. One perl script later and things have a 5% speed
* up on a sparc2. Thanks to Richard Outerbridge
* <[email protected]> for pointing this out.
*/
/* clear the top bits on machines with 8byte longs */
/* shift left by 2 */
r = ROTATE(r, 29) & 0xffffffffL;
l = ROTATE(l, 29) & 0xffffffffL;
s = ks->ks->deslong;
/*
* I don't know if it is worth the effort of loop unrolling the inner
* loop
*/
if (enc) {
#ifdef DES_UNROLL
D_ENCRYPT(l, r, 0); /* 1 */
D_ENCRYPT(r, l, 2); /* 2 */
D_ENCRYPT(l, r, 4); /* 3 */
D_ENCRYPT(r, l, 6); /* 4 */
D_ENCRYPT(l, r, 8); /* 5 */
D_ENCRYPT(r, l, 10); /* 6 */
D_ENCRYPT(l, r, 12); /* 7 */
D_ENCRYPT(r, l, 14); /* 8 */
D_ENCRYPT(l, r, 16); /* 9 */
D_ENCRYPT(r, l, 18); /* 10 */
D_ENCRYPT(l, r, 20); /* 11 */
D_ENCRYPT(r, l, 22); /* 12 */
D_ENCRYPT(l, r, 24); /* 13 */
D_ENCRYPT(r, l, 26); /* 14 */
D_ENCRYPT(l, r, 28); /* 15 */
D_ENCRYPT(r, l, 30); /* 16 */
#else
for (i = 0; i < 32; i += 4) {
D_ENCRYPT(l, r, i + 0); /* 1 */
D_ENCRYPT(r, l, i + 2); /* 2 */
}
#endif
} else {
#ifdef DES_UNROLL
D_ENCRYPT(l, r, 30); /* 16 */
D_ENCRYPT(r, l, 28); /* 15 */
D_ENCRYPT(l, r, 26); /* 14 */
D_ENCRYPT(r, l, 24); /* 13 */
D_ENCRYPT(l, r, 22); /* 12 */
D_ENCRYPT(r, l, 20); /* 11 */
D_ENCRYPT(l, r, 18); /* 10 */
D_ENCRYPT(r, l, 16); /* 9 */
D_ENCRYPT(l, r, 14); /* 8 */
D_ENCRYPT(r, l, 12); /* 7 */
D_ENCRYPT(l, r, 10); /* 6 */
D_ENCRYPT(r, l, 8); /* 5 */
D_ENCRYPT(l, r, 6); /* 4 */
D_ENCRYPT(r, l, 4); /* 3 */
D_ENCRYPT(l, r, 2); /* 2 */
D_ENCRYPT(r, l, 0); /* 1 */
#else
for (i = 30; i > 0; i -= 4) {
D_ENCRYPT(l, r, i - 0); /* 16 */
D_ENCRYPT(r, l, i - 2); /* 15 */
}
#endif
}
/* rotate and clear the top bits on machines with 8byte longs */
l = ROTATE(l, 3) & 0xffffffffL;
r = ROTATE(r, 3) & 0xffffffffL;
FP(r, l);
data[0] = l;
data[1] = r;
l = r = t = u = 0;
}
开发者ID:NickAger,项目名称:elm-slider,代码行数:91,代码来源:des_enc.c
示例16: fcrypt_body
void fcrypt_body (DES_LONG * out, DES_key_schedule * ks, DES_LONG Eswap0, DES_LONG Eswap1)
{
register DES_LONG l, r, t, u;
#ifdef DES_PTR
register const unsigned char *des_SP = (const unsigned char *) DES_SPtrans;
#endif
register DES_LONG *s;
register int j;
register DES_LONG E0, E1;
l = 0;
r = 0;
s = (DES_LONG *) ks;
E0 = Eswap0;
E1 = Eswap1;
for (j = 0; j < 25; j++)
{
#ifndef DES_UNROLL
register int i;
for (i = 0; i < 32; i += 4)
{
D_ENCRYPT (l, r, i + 0); /* 1 */
D_ENCRYPT (r, l, i + 2); /* 2 */
}
#else
D_ENCRYPT (l, r, 0); /* 1 */
D_ENCRYPT (r, l, 2); /* 2 */
D_ENCRYPT (l, r, 4); /* 3 */
D_ENCRYPT (r, l, 6); /* 4 */
D_ENCRYPT (l, r, 8); /* 5 */
D_ENCRYPT (r, l, 10); /* 6 */
D_ENCRYPT (l, r, 12); /* 7 */
D_ENCRYPT (r, l, 14); /* 8 */
D_ENCRYPT (l, r, 16); /* 9 */
D_ENCRYPT (r, l, 18); /* 10 */
D_ENCRYPT (l, r, 20); /* 11 */
D_ENCRYPT (r, l, 22); /* 12 */
D_ENCRYPT (l, r, 24); /* 13 */
D_ENCRYPT (r, l, 26); /* 14 */
D_ENCRYPT (l, r, 28); /* 15 */
D_ENCRYPT (r, l, 30); /* 16 */
#endif
t = l;
l = r;
r = t;
}
l = ROTATE (l, 3) & 0xffffffffL;
r = ROTATE (r, 3) & 0xffffffffL;
PERM_OP (l, r, t, 1, 0x55555555L);
PERM_OP (r, l, t, 8, 0x00ff00ffL);
PERM_OP (l, r, t, 2, 0x33333333L);
PERM_OP (r, l, t, 16, 0x0000ffffL);
PERM_OP (l, r, t, 4, 0x0f0f0f0fL);
out[0] = r;
out[1] = l;
}
开发者ID:274914765,项目名称:C,代码行数:65,代码来源:fcrypt_b.c
示例17: _getEigenVectors
static void _getEigenVectors(Mat4* vout, Vec3* dout, Mat4 a)
{
int n = 3;
int j,iq,ip,i;
double tresh, theta, tau, t, sm, s, h, g, c;
int nrot;
Vec3 b;
Vec3 z;
Mat4 v;
Vec3 d;
v = Mat4::IDENTITY;
for(ip = 0; ip < n; ip++)
{
_getElement(b, ip) = a.m[ip + 4 * ip];
_getElement(d, ip) = a.m[ip + 4 * ip];
_getElement(z, ip) = 0.0;
}
nrot = 0;
for(i = 0; i < 50; i++)
{
sm = 0.0;
for(ip = 0; ip < n; ip++) for(iq = ip+1; iq < n; iq++) sm += fabs(a.m[ip + 4 * iq]);
if( fabs(sm) < FLT_EPSILON )
{
v.transpose();
*vout = v;
*dout = d;
return;
}
if (i < 3)
tresh = 0.2 * sm / (n*n);
else
tresh = 0.0;
for(ip = 0; ip < n; ip++)
{
for(iq = ip + 1; iq < n; iq++)
{
g = 100.0 * fabs(a.m[ip + iq * 4]);
float dmip = _getElement(d, ip);
float dmiq = _getElement(d, iq);
if( i>3 && fabs(dmip) + g == fabs(dmip) && fabs(dmiq) + g == fabs(dmiq) )
{
a.m[ip + 4 * iq] = 0.0;
}
else if (fabs(a.m[ip + 4 * iq]) > tresh)
{
h = dmiq - dmip;
if (fabs(h) + g == fabs(h))
{
t=(a.m[ip + 4 * iq])/h;
}
else
{
theta = 0.5 * h / (a.m[ip + 4 * iq]);
t=1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
if (theta < 0.0) t = -t;
}
c = 1.0 / sqrt(1+t*t);
s = t*c;
tau = s / (1.0+c);
h = t * a.m[ip + 4 * iq];
_getElement(z, ip) -= (float)h;
_getElement(z, iq) += (float)h;
_getElement(d, ip) -= (float)h;
_getElement(d, iq) += (float)h;
a.m[ip + 4 * iq]=0.0;
for(j = 0; j < ip; j++) { ROTATE(a,j,ip,j,iq); }
for(j = ip + 1; j < iq; j++) { ROTATE(a,ip,j,j,iq); }
for(j = iq + 1; j < n; j++) { ROTATE(a,ip,j,iq,j); }
for(j = 0; j < n; j++) { ROTATE(v,j,ip,j,iq); }
nrot++;
}
}
}
for(ip = 0; ip < n; ip++)
{
_getElement(b, ip) += _getElement(z, ip);
_getElement(d, ip) = _getElement(b, ip);
_getElement(z, ip) = 0.0f;
}
}
v.transpose();
*vout = v;
*dout = d;
return;
}
开发者ID:RyunosukeOno,项目名称:rayjack,代码行数:94,代码来源:CCOBB.cpp
示例18: jacobi
int jacobi(double (*a)[3], double d[3], double (*v)[3], int *nrot)
{
int j,iq,ip,i;
double tresh,theta,tau,t,sm,s,h,g,c;
static double b[3];
static double z[3];
for (ip = 0; ip < 3; ip++) {
for (iq = 0; iq < 3; iq++) {
v[ip][iq]=0.0;
}
v[ip][ip]=1.0;
}
for (ip = 0; ip < 3; ip++) {
b[ip] = d[ip] = a[ip][ip];
z[ip] = 0.0;
}
*nrot=0;
for (i = 0; i < ITERATIONMAX; i++) {
sm = 0.0;
for (ip = 0; ip < 3-1; ip++) {
for (iq = ip+1; iq < 3; iq++) {
sm += fabs(a[ip][iq]);
}
}
/* the normal return, which relies on quadratic convergence to
machine underflow. */
if (sm == 0.0) {
return (0);
}
if (i < 3) {
tresh=0.2*sm/(3*3);
} else {
tresh=0.0;
}
for (ip = 0; ip < 3-1; ip++) {
for (iq = ip+1; iq < 3; iq++) {
g=100.0*fabs(a[ip][iq]);
if (i > 3 &&
(fabs(d[ip])+g) == fabs(d[ip]) &&
(fabs(d[iq])+g) == fabs(d[iq])) {
a[ip][iq]=0.0;
} else if (fabs(a[ip][iq]) > tresh) {
h=d[iq]-d[ip];
if ((fabs(h)+g) == fabs(h)) {
t=(a[ip][iq])/h;
} else {
theta=0.5*h/(a[ip][iq]);
t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
if (theta < 0.0) {
t = -t;
}
}
c=1.0/sqrt(1+t*t);
s=t*c;
tau=s/(1.0+c);
h=t*a[ip][iq];
z[ip] -= h;
z[iq] += h;
d[ip] -= h;
d[iq] += h;
a[ip][iq]=0.0;
for (j = 0; j <= ip-1; j++) {
ROTATE(a,j,ip,j,iq);
}
for (j = ip+1; j <= iq-1; j++) {
ROTATE(a,ip,j,j,iq);
}
for (j = iq+1; j < 3; j++) {
ROTATE(a,ip,j,iq,j);
}
for (j = 0; j < 3; j++) {
ROTATE(v,j,ip,j,iq);
}
++(*nrot);
}
}
}
for (ip = 0; ip < 3; ip++) {
b[ip] += z[ip];
d[ip] = b[ip];
z[ip] = 0.0;
}
}
fprintf(stderr, "jacobi(): too many iterations\n");
return (-1);
}
开发者ID:Milkyway-at-home,项目名称:nemo,代码行数:92,代码来源:p2m2.c
示例19: des_encrypt2
void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
{
DES_LONG l,r,t,u;
#ifdef DES_PTR
const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
#endif
#ifndef DES_UNROLL
int i;
#endif
DES_LONG *s;
r=data[0];
l=data[1];
/* Things have been modified so that the initial rotate is
* done outside the loop. This required the
* des_SPtrans values in sp.h to be rotated 1 bit to the right.
* One perl script later and things have a 5% speed up on a sparc2.
* Thanks to Richard Outerbridge <[email protected]>
* for pointing this out. */
/* clear the top bits on machines with 8byte longs */
r=ROTATE(r,29)&0xffffffffL;
l=ROTATE(l,29)&0xffffffffL;
s=ks->ks.deslong;
/* I don't know if it is worth the effort of loop unrolling the
* inner loop */
if (enc)
{
#ifdef DES_UNROLL
D_ENCRYPT(l,r, 0); /* 1 */
D_ENCRYPT(r,l, 2); /* 2 */
D_ENCRYPT(l,r, 4); /* 3 */
D_ENCRYPT(r,l, 6); /* 4 */
D_ENCRYPT(l,r, 8); /* 5 */
D_ENCRYPT(r,l,10); /* 6 */
D_ENCRYPT(l,r,12); /* 7 */
D_ENCRYPT(r,l,14); /* 8 */
D_ENCRYPT(l,r,16); /* 9 */
D_ENCRYPT(r,l,18); /* 10 */
D_ENCRYPT(l,r,20); /* 11 */
D_ENCRYPT(r,l,22); /* 12 */
D_ENCRYPT(l,r,24); /* 13 */
D_ENCRYPT(r,l,26); /* 14 */
D_ENCRYPT(l,r,28); /* 15 */
D_ENCRYPT(r,l,30); /* 16 */
#else
for (i=0; i<32; i+=8)
{
D_ENCRYPT(l,r,i+0); /* 1 */
D_ENCRYPT(r,l,i+2); /* 2 */
D_ENCRYPT(l,r,i+4); /* 3 */
D_ENCRYPT(r,l,i+6); /* 4 */
}
#endif
}
else
{
#ifdef DES_UNROLL
D_ENCRYPT(l,r,30); /* 16 */
D_ENCRYPT(r,l,28); /* 15 */
D_ENCRYPT(l,r,26); /* 14 */
D_ENCRYPT(r,l,24); /* 13 */
D_ENCRYPT(l,r,22); /* 12 */
D_ENCRYPT(r,l,20); /* 11 */
D_ENCRYPT(l,r,18); /* 10 */
D_ENCRYPT(r,l,16); /* 9 */
D_ENCRYPT(l,r,14); /* 8 */
D_ENCRYPT(r,l,12); /* 7 */
D_ENCRYPT(l,r,10); /* 6 */
D_ENCRYPT(r,l, 8); /* 5 */
D_ENCRYPT(l,r, 6); /* 4 */
D_ENCRYPT(r,l, 4); /* 3 */
D_ENCRYPT(l,r, 2); /* 2 */
D_ENCRYPT(r,l, 0); /* 1 */
#else
for (i=30; i>0; i-=8)
{
D_ENCRYPT(l,r,i-0); /* 16 */
D_ENCRYPT(r,l,i-2); /* 15 */
D_ENCRYPT(l,r,i-4); /* 14 */
D_ENCRYPT(r,l,i-6); /* 13 */
}
#endif
}
/* rotate and clear the top bits on machines with 8byte longs */
data[0]=ROTATE(l,3)&0xffffffffL;
data[1]=ROTATE(r,3)&0xffffffffL;
l=r=t=u=0;
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:90,代码来源:des_enc.c
示例20: main
// ./next_gen "# of permutations" stem0 stem1 stem2 ...
int main(int argc, unsigned char **argv) {
char phrase[59] = "I would much rather hear more about your whittling project";
unsigned int permutations = atou((char *)argv[1]);
sseK00_19 = _mm_set1_epi32(0x5a827999);
sseK20_39 = _mm_set1_epi32(0x6ed9eba1);
sseK40_59 = _mm_set1_epi32(0x8f1bbcdc);
sseK60_79 = _mm_set1_epi32(0xca62c1d6);
best_stem = malloc(sizeof(char) * 5);
shortest_d = 180;
// Get finished context for phrase
SHA_CTX *phrase_ctx = malloc(sizeof(SHA_CTX));
sha1_full(phrase_ctx, phrase);
// Load prefixes
unsigned char **prefixes = malloc(sizeof(char *) * PREFIX_COUNT);
int p = 0;
for(p = 0;p < PREFIX_COUNT;p++)
prefixes[p] = argv[2 + p];
// Get chaining contexts for suffixes
SHA_CTX *prefix_ctxs = malloc(sizeof(SHA_CTX) * PREFIX_COUNT);
for(p = 0;p < PREFIX_COUNT;p++)
sha1_partial(&prefix_ctxs[p], prefixes[p]);
struct vector_ctx *vc = malloc(sizeof(struct vector_ctx) * PREFIX_COUNT/4);
struct vector_ctx *vc_ptr = vc;
SHA_CTX *prefix_ptr = prefix_ctxs;
for(p = 0;p < PREFIX_COUNT;p+=4) {
vectorize_prefixes(vc_ptr, prefix_ptr);
prefix_ptr += 4;
vc_ptr += 1;
}
// Allocate memory for expanded message template
uint32_t *w = malloc(sizeof(uint32_t) * 80);
int w_i = 0;
// We only hash suffixes that are 5 bytes long
// w[0] prefix_stem
// w[1] current final char + some other stuff and zeros
// w[2]-w[14]
// Expanded message blocks 2-14 are always 0x0000000...
for(w_i = 2;w_i < 15;w_i++)
w[w_i] = 0;
// w[15] is the size of the message
w[15] = 552;
// w[16] - stem constant - W13 ^ W8 ^ W2 ^ W0 => W0 <<< 1
// w[17] - changing lots
// w[18] - constant
w[18] = ROTATE(w[15], 1);
// w[19] - stem constant
// w[20] - changing lots
uint32_t *stem_w = malloc(sizeof(uint32_t) * 80);
uint32_t *stem_x = malloc(sizeof(uint32_t) * 80);
init_lut();
struct vector_ctx *my_vc = malloc(sizeof(struct vector_ctx) * PREFIX_COUNT/2);
int i = 0;
char suffix_stem[5] = "!!!!";
for(i = 0;i < permutations;i++) {
memcpy(stem_w, w, 80 * sizeof(uint32_t));
memcpy(my_vc, vc, sizeof(struct vector_ctx) * PREFIX_COUNT/2);
int dist = shortest_distance(phrase_ctx, my_vc, suffix_stem, stem_w, stem_x);
next_stem(suffix_stem);
}
free(vc);
free(my_vc);
free(w);
free(stem_w);
free(stem_x);
// Print shortest_distance and the 5 char ending.
printf("%d,%s,%d\n", shortest_d, best_stem, best_last+33);
}
开发者ID:bpot,项目名称:sha1_hashing_ey_2009,代码行数:91,代码来源:next_gen.c
注:本文中的ROTATE函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论