Search Results

Search found 614 results on 25 pages for 'vectors'.

Page 3/25 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • C# AES returns wrong Test Vectors

    - by ralu
    I need to implement some crypto protocol on C# and want to say that this is my first project in C#. After spending some time to get used on C# I found out that I am unable to get compliant AES vectors. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.IO; namespace ConsoleApplication1 { class Program { public static void Main() { try { //test vectors from "ecb_vk.txt" byte[] key = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] encTest = { 0x0e, 0xdd, 0x33, 0xd3, 0xc6, 0x21, 0xe5, 0x46, 0x45, 0x5b, 0xd8, 0xba, 0x14, 0x18, 0xbe, 0xc8 }; AesManaged aesAlg = new AesManaged(); aesAlg.BlockSize = 128; aesAlg.Key = key; aesAlg.Mode = CipherMode.ECB; ICryptoTransform encryptor = aesAlg.CreateEncryptor(); MemoryStream msEncrypt = new MemoryStream(); CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); StreamWriter swEncrypt = new StreamWriter(csEncrypt); swEncrypt.Write(data); swEncrypt.Close(); csEncrypt.Close(); msEncrypt.Close(); aesAlg.Clear(); byte[] encr; encr = msEncrypt.ToArray(); string datastr = BitConverter.ToString(data); string encrstr = BitConverter.ToString(encr); string encTestStr = BitConverter.ToString(encTest); Console.WriteLine("data: {0}", datastr); Console.WriteLine("encr: {0}", encrstr); Console.WriteLine("should: {0}", encTestStr); Console.ReadKey(); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); } } } } Output is wrong: data: 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 encr: A0-3C-C2-22-A4-32-F7-C9-BA-36-AE-73-66-BD-BB-A3 should: 0E-DD-33-D3-C6-21-E5-46-45-5B-D8-BA-14-18-BE-C8 I am sure that there is correct AES implementation in C#, so I need some advice from C# wizard to help whit this. Thanks

    Read the article

  • how to loop through an array of vectors in C#

    - by Robert
    Hello everyone,I now have an array of vectors: static Vector3[] axes = new Vector3[] { Vector3.UnitX, Vector3.UnitY, Vector3.UnitZ }; and I want to loop through it,the code I write is: for(int i=0;i<axes.Length;i++) { do sth. about axes[i]; } However,it doesnt work and gets into infinite loop,could anyone help? thx.

    Read the article

  • Matlab - Find point of intersection between two vectors

    - by Silv3rSurf
    I have a very simple matlab question. What is the easiest way to find the point of intersection between two vectors. I am not familiar with the various matlab fuctions -- it seems like there should be one for this. For example if I have one vector from (0,0) to (6,6) and another vector from (0,6) to (6,0), I need to determine that they intersect at (3,3) Thanks.

    Read the article

  • why no += operator for vectors in stl

    - by Akshay Bhat
    I am curious? What high fundu logic goes behind not implementing: result+=vector1; where both result and vector1 are stl vectors. Note: i know how to implement that bit, but i need to know what logic, the sages who designed STL were using when they chose not to implement this feature?

    Read the article

  • how to fast compute distance between high dimension vectors

    - by chyojn
    assume there are three group of high dimension vectors: {a_1, a_2, ..., a_N}, {b_1, b_2, ... , b_N}, {c_1, c_2, ..., c_N}. each of my vector can be represented as: x = a_i + b_j + c_k, where 1 <=i, j, k <= N. then the vector is encoded as (i, j, k) wich is then can be decoded as x = a_i + b_j + c_k. my question is, if there are two vector: x = (i_1, j_1, k_1), y = (i_2, j_2, k_2), is there a method to compute the euclidian distance of these two vector without decode x and y.

    Read the article

  • Creating a series of vectors from a vector

    - by bluetongue
    I have a simple two vector dataframe (length=30) that looks something like this: > mDF Param1 w.IL.L 1 AuZgFw 0.5 2 AuZfFw 2 3 AuZgVw 74.3 4 AuZfVw 20.52 5 AuTgIL 80.9 6 AuTfIL 193.3 7 AuCgFL 0.2 8 ... I'd like to use each of the rows to form 30 single value numeric vectors with the name of the vector taken from mDF$Param1, so that: > AuZgFw [1] 0.5 etc I've tried melting and casting, but I suspect there may be an easier way?? Thanks in advance BT

    Read the article

  • Do classes which have a vector has a member have memory issues

    - by user263766
    I am just starting out C++, so sorry if this is a dumb question. I have a class Braid whose members are vectors. I have not written an assignment operator. When I do a lot of assignments to an object of the type Braid, I run into memory issues :- 0 0xb7daff89 in _int_malloc () from /lib/libc.so.6 #1 0xb7db2583 in malloc () from /lib/libc.so.6 #2 0xb7f8ac59 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6 #3 0x0804d05e in __gnu_cxx::new_allocator<int>::allocate (this=0xbf800204, __n=1) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/ext/new_allocator.h:89 #4 0x0804cb0e in std::_Vector_base<int, std::allocator<int> >::_M_allocate (this=0xbf800204, __n=1) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/bits/stl_vector.h:140 #5 0x0804c086 in _Vector_base (this=0xbf800204, __n=1, __a=...) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/bits/stl_vector.h:113 #6 0x0804b4b7 in vector (this=0xbf800204, __x=...) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/bits/stl_vector.h:242 #7 0x0804b234 in Braid (this=0xbf800204) at braid.h:13 #8 0x080495ed in Braid::cycleBraid (this=0xbf8001b4) at braid.cpp:191 #9 0x080497c6 in Braid::score (this=0xbf800298, b=...) at braid.cpp:251 #10 0x08049c46 in Braid::evaluateMove (this=0xbf800468, move=1, pos=0, depth=2, b=...) I suspect that these memory issues are because the vectors are getting resized. What I want to know is whether objects of type Braid automatically expand when its members expand? he code I am writing is really long so I will post the section which is causing the problems. Here is the relevant section of the code :- class Braid { private : vector<int> braid; //Stores the braid. int strands; vector < vector<bool> > history; vector < vector<bool> > CM; public : Braid () : strands(0) {} Braid operator * (Braid); Braid* inputBraid(int,vector<int>); int printBraid(); int printBraid(vector<vector<int>::iterator>); vector<int>::size_type size() const; ..... ..... } Here is the function which causes the issue :- int Braid::evaluateMove(int move,int pos,int depth,Braid b) { int netscore = 0; Braid curr(*this); curr = curr.move(move,pos); netscore += curr.score(b); while(depth > 1) { netscore += curr.evaluateMove(1,0,depth,b); netscore += curr.evaluateMove(2,0,depth,b); for(int i = 0; i < braid.size();++i) { netscore += curr.evaluateMove(3,i,depth,b); netscore += curr.evaluateMove(4,i,depth,b); netscore += curr.evaluateMove(5,i,depth,b); curr = curr.cycleBraid(); netscore += curr.evaluateMove(6,0,depth,b); } --depth; } return netscore; }

    Read the article

  • 3D Math: Calculate Bank (Roll) angle from Look and Up orthogonal vectors

    - by 742
    I hope this is the proper location to ask this question which is the same as this one, but expressed as pure math instead of graphically (at least I hope I translated the problem to math correctly). Considering: two vectors that are orthogonal: Up (ux, uy, uz) and Look (lx, ly, lz) a plane P which is perpendicular to Look (hence including Up) Y1 which is the projection of Y (vertical axis) along Look onto P Question: what is the value of the angle between Y1 and Up? As mathematicians will agree, this is a very basic question, but I've been scratching my head for at least two weeks without being able to visualize how to project Y onto P... maybe now too old for finding solutions to school exercises. I'm looking for the trigonometric solution, not a solution using a matrix. Thanks.

    Read the article

  • Pointing to vectors

    - by Matt Munson
    #include <iostream> #include <vector> using namespace std; int main () { vector <int> qwerty; qwerty.push_back(5); vector <int>* p = &qwerty; cout << p[0]; //error: no match for 'operator<<' in 'std::cout << * p' } I'm generally unclear on how to use pointers with vectors, so I'm pretty mystified as to why this is not working. To my mind, this should print 5 to screen.

    Read the article

  • Icons in Silverlight: Images vs. Vectors

    - by Shnitzel
    I like using the vector drawing feature of Expression Blend to create icons. That way I can change colors easily on my icons without having to resort to an image editor. But my question is... Say I have a treeview control that has an icon next to each tree element and say I have hundreds of elements. Do you think using images is faster - performance wise than using vector icons? B/c I'd rather use vectors but I'm wondering about performance concerns.

    Read the article

  • Matlab - Propagate unit vectors on to the edge of shape boundaries

    - by Graham
    Hi I have a set of unit vectors which I want to propagate on to the edge of shape boundary defined by a binary image. The shape boundary is defined by a 1px wide white edge. I also have the coordinates of these points stored in a 2 row by n column matrix. The shape forms a concave boundary with no holes within itself made of around 2500 points. What would be the best method to do this? Are there some sort of ray tracing algorithms that could be used? Or would it be a case of taking the unit vector and multiplying it by a scalar and testing after multiplication if the end point of the vector is outside the shape boundary. When the end point of the unit vector is outside the shape, just find the point of intersection? Thank you very much in advance for any help!

    Read the article

  • Removing duplicates (within a given tolerance) from a Numpy array of vectors

    - by Brendan
    I have an Nx5 array containing N vectors of form 'id', 'x', 'y', 'z' and 'energy'. I need to remove duplicate points (i.e. where x, y, z all match) within a tolerance of say 0.1. Ideally I could create a function where I pass in the array, columns that need to match and a tolerance on the match. Following this thread on Scipy-user, I can remove duplicates based on a full array using record arrays, but I need to just match part of an array. Moreover this will not match within a certain tolerance. I could laboriously iterate through with a for loop in Python but is there a better Numponic way?

    Read the article

  • Selecting size of vector of vectors

    - by xbonez
    I have a class called Grid that declares a vector of vectors like this: typedef vector<int> row; typedef vector<row> myMatrix; myMatrix sudoku_; The constructor looks like this: grid::grid() : sudoku_(9,9) { } As you can see, the constructor is initializing it to be a 9x9 grid. How can I make it work so that the user is asked for a number, say n, and the grid is initialized n x n ?

    Read the article

  • Vectors for a 2D/3D World in Java

    - by jax
    I reading about Mathematics in Games and am wondering what is the best way to represent a Vector location in Java. I know there is a Vector class but I don't think this is what I need. There is also a Matrix class which looks like it may be what I want (a 1 dimensional matrix maybe). In particular, if I were to create a location Vector such as: v(x,y,z) where x,y and z are the coordinates in 3D space, what would be the best way to represent this in Java. It would be nice if I could also add, subtract and find the dot-product of Vectors. ideas?

    Read the article

  • Would vector of vectors be contiguous?

    - by user1150989
    I need to allocate a vector of rows where row contains a vector of rows. I know that a vector would be contiguous. I wanted to know whether a vector of vectors would also be contiguous. Example code is given below vector<long> firstRow; firstRow.push_back(0); firstRow.push_back(1); vector<long> secondRow; secondRow.push_back(0); secondRow.push_back(1); vector< vector < long> > data; data.push_back(firstRow); data.push_back(secondRow); Would the sequence in memory be 0 1 0 1?

    Read the article

  • Basic C++ code for multiplication of 2 matrix or vectors (C++ beginner)

    - by Ice
    I am a new C++ user and I am also doing a major in Maths so thought I would try implement a simple calculator. I got some code off the internet and now I just need help to multiply elements of 2 matrices or vectors. Matrixf multiply(Matrixf const& left, Matrixf const& right) { // error check if (left.ncols() != right.nrows()) { throw std::runtime_error("Unable to multiply: matrix dimensions not agree."); } /* I have all the other part of the code for matrix*/ /** Now I am not sure how to implement multiplication of vector or matrix.**/ Matrixf ret(1, 1); return ret; }

    Read the article

  • Quickest way to compute the number of shared elements between two vectors

    - by shn
    Suppose I have two vectors of the same size vector< pair<float, NodeDataID> > v1, v2; I want to compute how many elements from both v1 and v2 have the same NodeDataID. For example if v1 = {<3.7, 22>, <2.22, 64>, <1.9, 29>, <0.8, 7>}, and v2 = {<1.66, 7>, <0.03, 9>, <5.65, 64>, <4.9, 11>}, then I want to return 2 because there are two elements from v1 and v2 that share the same NodeDataIDs: 7 and 64. What is the quickest way to do that in C++ ? Just for information, note that the type NodeDataIDs is defined as I use boost as: typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> myGraph; typedef myGraph::vertex_descriptor NodeDataID; But it is not important since we can compare two NodeDataID using the operator == (that is, possible to do v1[i].second == v2[j].second)

    Read the article

  • Programmatically creating vector arrows in KML

    - by mettadore
    Does anyone have any practical examples of programmatically drawing icons as vectors in KML? Specifically, I have data with a magnitude and an azimuth at given coordinates, and I would like to have icons (or another graphical element) generated based on these values. Some thoughts on how I might approach it: Image directory (a brute force way): Make an image director of 360 different image files (probably batch rotate a single image) each pointing in a cooresponding azimuth. I've seen things like "Excel to KML," but am looking for code that I can use within a program, rather than a web utility. Issue: Arrow does not contain magnitude context, so that would have to be a label. I'd rather dynamically lengthen the arrow. Line creation in KML: Perhaps create a formula that creates a line with the origin at the coordinate points, with the length of the line proportional to the magnitute, and angled according to azimuth. There would then be two more lines, perhaps 30 degrees or so extending from the end of the previous line to make the arrow head. Issues: Not a separate image icon, so not sure how it would work in KML. Also not sure how easy it would be to generate this algorithm. Separate image generation: Perhaps create a PHP file that uses imagemagick or something similar to dynamically generate a .png file in a similar method to the above, and then link to the icon using the URI "domain.tld/imagegen.php?magnitude=magvalue&azimuth=azmvalue". Issue: Still have the problem of actually writing the algorithm for image generation. So, the question: has anyone else come up with solutions for programmatic vector (rather than merely arrow) generation?

    Read the article

  • Strange problem with vectors.

    - by Catalin Dumitru
    I have a really strange problem with stl vectors in which the wrong destructor is called for the right object when I call the erase method if that makes any sense. My code looks something like this: for(vector<Category>::iterator iter = this->children.begin(); iter != this->children.end(); iter++) { if((*iter).item == item) { this->children.erase(iter); return; } ------------------------- } It's just a simple function that finds the element in the vector which has some item to be searched, and removes said element from the vector. My problem is than when the erase function is called, and thus the object which the iterator is pointing at is being destroyed, the wrong destructor is being called. More specific the destructor of the last element in the vector is being called, and not of the actual object being removed. Thus the memory is being removed from the wrong object, which will still be an element in the vector, and the actual object which is removed from the vector, still has all of it's memory intact. The costructor of the object looks like this: Category::Category(const Category &from) { this->name = from.name; for(vector<Category>::const_iterator iter = from.children.begin(); iter != from.children.end(); iter++) this->children.push_back((*iter)); this->item = new QTreeWidgetItem; } And the destructor Category::~Category() { this->children.clear(); if(this->item != NULL) { QTreeWidgetItem* parent = this->item->parent(); if(parent != NULL) parent->removeChild(this->item); delete this->item; } }

    Read the article

  • Method of transforming 3D vectors with a matrix

    - by Drew Noakes
    I've been doing some reading on transforming Vector3 with matrices, and am tossing up digging deeper into the math and coding this myself versus using existing code. For whatever reason my school curriculum never included matrices, so I'm filling a gap in my knowledge. Thankfully I only need a few simple things, I think. Context is that I'm programming a robot for the RoboCup 3D league. I'm coding it in C# but it'll have to run on Mono. Ideally I wouldn't use any existing graphics libraries for this (WinForms/WPF/XNA) as all I really need is a neat subset of matrix transformations. Specifically, I need translation and x/y/z rotations, and a way of combining multiple transformations into a single matrix. This will then be applied to my own Vector3 type to produce the transformed Vector3. I've read different advice about this. For example, some model the transformation with a 4x3 matrix, others with a 4x4 matrix. Also, some examples show that you need a forth value for the vector's matrix of 1. What happens to this value when it's included in the output? [1 0 0 0] [x y z 1] * [0 1 0 0] = [a b c d] [0 0 1 0] [2 4 6 1] The parts I'm missing are: What sizes my matrices should be Compositing transformations by multiplying the transformation matrices together Transforming 3D vectors with the resulting matrix As I mostly just want to get this running, any psuedo-code would be great. Information about what matrix values perform what transformations is quite clearly defined on many pages, so need not be discussed here unless you're very keen :)

    Read the article

  • How to identify multiple identical pairs in two vectors

    - by Sacha Epskamp
    In my graph-package (as in graph theory, nodes connected by edges) I have a vector indicating for each edge the node of origin from, a vector indicating for each edge the node of destination to and a vector indicating the curve of each edge curve. By default I want edges to have a curve of 0 if there is only one edge between two nodes and curve of 0.2 if there are two edges between two nodes. The code that I use now is a for-loop, and it is kinda slow: curve <- rep(0,5) from<-c(1,2,3,3,2) to<-c(2,3,4,2,1) for (i in 1:length(from)) { if (any(from==to[i] & to==from[i])) { curve[i]=0.2 } } So basically I look for each edge (one index in from and one in to) if there is any other pair in from and to that use the same nodes (numbers). What I am looking for are two things: A way to identify if there is any pair of nodes that have two edges between them (so I can omit the loop if not) A way to speed up this loop # EDIT: To make this abit clearer, another example: from <- c(4L, 6L, 7L, 8L, 1L, 9L, 5L, 1L, 2L, 1L, 10L, 2L, 6L, 7L, 10L, 4L, 9L) to <- c(1L, 1L, 1L, 2L, 3L, 3L, 4L, 5L, 6L, 7L, 7L, 8L, 8L, 8L, 8L, 10L, 10L) cbind(from,to) from to [1,] 4 1 [2,] 6 1 [3,] 7 1 [4,] 8 2 [5,] 1 3 [6,] 9 3 [7,] 5 4 [8,] 1 5 [9,] 2 6 [10,] 1 7 [11,] 10 7 [12,] 2 8 [13,] 6 8 [14,] 7 8 [15,] 10 8 [16,] 4 10 [17,] 9 10 In these two vectors, pair 3 is identical to pair 10 (both 1 and 7 in different orders) and pairs 4 and 12 are identical (both 2 and 8). So I would want curve to become: [1,] 0.0 [2,] 0.0 [3,] 0.2 [4,] 0.2 [5,] 0.0 [6,] 0.0 [7,] 0.0 [8,] 0.0 [9,] 0.0 [10,] 0.2 [11,] 0.0 [12,] 0.2 [13,] 0.0 [14,] 0.0 [15,] 0.0 [16,] 0.0 [17,] 0.0 (as I vector, I transposed twice to get row numbers).

    Read the article

  • Computing the scalar product of two vectors in C++

    - by HowardRoark
    I am trying to write a program with a function double_product(vector<double> a, vector<double> b) that computes the scalar product of two vectors. The scalar product is $a_{0}b_{0}+a_{1}b_{1}+...+a_{n-1}b_{n-1}$. Here is what I have. It is a mess, but I am trying! #include <iostream> #include <vector> using namespace std; class Scalar_product { public: Scalar_product(vector<double> a, vector<double> b); }; double scalar_product(vector<double> a, vector<double> b) { double product = 0; for (int i = 0; i <= a.size()-1; i++) for (int i = 0; i <= b.size()-1; i++) product = product + (a[i])*(b[i]); return product; } int main() { cout << product << endl; return 0; }

    Read the article

  • Vectors or Java arrays for Tetris?

    - by StackedCrooked
    I'm trying to create a Tetris-like game with Clojure and I'm having some trouble deciding the data structure for the playing field. I want to define the playing field as a mutable grid. The individual blocks are also grids, but don't need to be mutable. My first attempt was to define a grid as a vector of vectors. For example an S-block looks like this: :s-block { :grids [ [ [ 0 1 1 ] [ 1 1 0 ] ] [ [ 1 0 ] [ 1 1 ] [ 0 1 ] ] ] } But that turns out to be rather tricky for simple things like iterating and painting (see the code below). For making the grid mutable my initial idea was to make each row a reference. But then I couldn't really figure out how to change the value of a specific cell in a row. One option would have been to create each individual cell a ref instead of each row. But that feels like an unclean approach. I'm considering using Java arrays now. Clojure's aget and aset functions will probably turn out to be much simpler. However before digging myself in a deeper mess I want to ask ideas/insights. How would you recommend implementing a mutable 2d grid? Feel free to share alternative approaches as well. Source code current state: Tetris.clj (rev452)

    Read the article

  • passing multiple vectors to function by reference (using structure)

    - by madman
    Hi StackOverflow, Can someone tell me the correct way of passing multiple vectors to a function that can take only a single argument? (specifically for pthread_create (..) function) I tried the following but it does not seem to work :-( First, I created the following structure struct ip2 { void* obj; int dim; int n_s; vector<vector<vector<double> > > *wlist; vector<int> *nrsv; struct model *pModel; }; The threads that I have created actually needs all these parameters. Since im using pthreads_create I put all this in a structure and then passed the pointer to the structure as an argument to pthread_create (as shown). some_fxn() { //some code struct ip2 ip; ip.obj=(void*) this; ip.n_s=n_s; ip.wlist=&wlist; ip.nrsv=&nrsv; ip.pModel=pModel; ip.dim=dim; pthread_create(&callThd1[lcntr], &attr1, &Cls::Entry, (void*) &ip); } The Entry method looks something like this. void* Cls::Entry(void *ip) { struct ip2 *x; x = (struct ip2 *)ip; (reinterpret_cast<Cls1 *>(x->obj))->Run(x->dim,x->n_s, x->wlist, x->nrsv, x->pModel); } The Run method looks something like this. void Run(int dim, int n_c, vector<vector<vector<double> > > *wlist, vector<int> *nrsv, struct model* pModel ) { //some code for(int k = 0; k < n_c; ++k) { //some code end = index + nrsv[k]; //some code } I get the following error when I try to compile the program. error: no match for ‘operator+’ in ‘index + *(((std::vector<int, std::allocator<int> >*)(((unsigned int)k) * 12u)) + nrsv)’ Can someone tell me how to do it the right way. Madhavan

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >